SQL query returns nothing if one field is empty



IBM's flagship relational database management system

SQL query returns nothing if one field is empty

Postby dont_be_hasty » Sat Aug 23, 2014 2:37 am

Hi,


I have a SQL query similar to the one below, that when one of the fields id empty it isnt returning the other information.

Table A: infoA1, infoA2, infoA3,
Table B: infoB1, infoB2


select a.infoA1, a.infoA2, a.infoA3, b.infoB2
from table1 a, table2 b
where a.infoA1 = b.infoB1
and a.infoA1 = 111


So here is my from problem sometimes infoB2 is empty. When this is empty then none of the information is returned.

Example
If i run the query for infoA1 = 111, infoB2 is not empty and the query returns back information. However if i run the query for infoA1 = 111, infoB2 is empty, then nothing gets returned.

Is there anyway to change this query so that is infoB2 is empty it will still return all the other data in the select query?

Any help at all would be appreciated.
dont_be_hasty
 
Posts: 1
Joined: Tue Aug 28, 2012 2:13 pm
Has thanked: 0 time
Been thanked: 0 time

Re: SQL query returns nothing if one field is empty

 

Re: SQL query returns nothing if one field is empty

Postby NicC » Sun Aug 24, 2014 6:03 pm

WHERE a.info1 = b.info1
OR b.info1 = ''
AND....

??
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post