If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL Query where all field are not null

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-10, 15:26
jkuyken jkuyken is offline
Registered User
 
Join Date: May 2010
Posts: 21
SQL Query where all field are not null

I have the following query:

Code:
SELECT
            StudenList.PER_ID,
            PRE.ELA_SCORE AS PRE_ELA,
            PRE.MTH_SCORE AS PRE_MTH,
            POST.ELA_SCALE AS POST_ELA,
            POST.MTH_SCALE AS POST_MTH
FROM    STUDENTLIST 
LEFT JOIN POST
    ON 
        ACE.PER_ID                = POST.PER_ID 
        AND POST.YEAR          = '10'
LEFT JOIN PRE
    ON 
        ACE.PER_ID                = PRE.PER_ID 
        AND PRE.YEAR            = '09'
It generates the list I need except because there are entries in the file for other subjects, such as social studies, I have rows where all four scores are null.

What is the most elegant way to filter out where all scores are null? Meaning if there is at least one score, I want the person to show in the list?

I could use a block of ands which are then or-ed, but there are 16 possible outcomes and I would have to correctly handle all of them. Seems like overkill. Any ideas?
Reply With Quote
  #2 (permalink)  
Old 06-08-10, 15:34
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There are indeed 16 combinations, but you want 15 of the them to return, so you only have to handle the one exception.

where x1 is not null or x2 is not null or x3 is not null or x4 is not null

Ady
Reply With Quote
  #3 (permalink)  
Old 06-08-10, 15:48
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
How about an exists subselect?
Dave
Reply With Quote
  #4 (permalink)  
Old 06-08-10, 22:03
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Another way:
WHERE COALESCE(x1 , x2 , x3 , x4) IS NOT NULL
Reply With Quote
Reply

Tags
all fields null, db2, sql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On