We help IT Professionals succeed at work.

SQL select - field value may be null

idiotsavant0207
on
I wrote a code to select 2 values from 3 tables, but have a problem since one of field value may be null. Please help!

The code is here:
select tbl1.name, tbl2.name from tbl1, tbl2, tbl3 where tbl1.ctid = tbl2.ctid and tbl1.iid = tbl3.iid and tbl3.oid = 5;

need to add to this code that tbl2.cid may be null?
Could you help me to do that? Thanks.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
you mean like this?

select tbl1.name, tbl2.name from tbl1, tbl2, tbl3 where (tbl1.ctid = tbl2.ctid or tbl2.cid is null) and tbl1.iid = tbl3.iid and tbl3.oid = 5;
CERTIFIED EXPERT
Commented:
you could also try with left join

select       tbl1.name,
      tbl2.name
from tbl1
left join tbl2 on tbl1.ctid = tbl2.ctid
inner join tbl3 on tbl1.iid = tbl3.iid and tbl3.oid = 5

Author

Commented:
thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.