Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"OR" condition

Status
Not open for further replies.

raji96

Programmer
Aug 7, 2001
64
US
Hi,

I have an sql like this

select distinct b.field3
from
table1 a,
table2 b,
table3 c,
table4 d
where
c.field5="something" and
c.feild2=b.field2 and
(((b.field2=a.field2) and (b.field3=a.field3)) or
((b.field2=c.field2) and (b.field3=c.field3)))


when this is executed ((b.field2=a.field2) and (b.field3=a.field3)) is basically has no rows in the table hence the condition is something like null or somerows.

But even though the second condition((b.field2=c.field2) and (b.field3=c.field3)) is true
the end result is always 'no rows return'.why is it?

since the second condition is true and has rows and the first one is false and since i am using or shouldn't it return the rows.
 
Hi raji,

Just as you said, if ((b.field2=c.field2) and (b.field3=c.field3)) is true for some rows, the query should return those rows. Have you checked that this condition is true for rows that also make (c.field5 = "something" and c.feild2 = b.field2) true?

Best regards,

Mauricio Peccorini
 
Also remember that boolean operations with null always return false.
 
When joining primary keys, you cannot use OR...this will create a cartesian product.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top