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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONFUSION about NULL behavior in Left outer join

Status
Not open for further replies.

aamkumar

Programmer
Apr 3, 2007
18
US
I have a confusin about using NULL option like the one shown below.

Select * from Table A TA,

Inner Join TabB TB on TB.Col1=TA.Col1.

Left outer join TabC TC.Col1=TA.Col1 and TC.Col2 isnull.

Where

TB.Col3=33

othercase is ...

Select * from Table A TA,

Inner Join TabB TB on TB.Col1=TA.Col1.

Left outer join TabC TC.Col1=TA.Col1

Where

TB.Col3=33

and TC.Col2 isnull


Why is the behavior different in both the cases....How is the Query one working or flowing by taking into consideration isnull value.


Please Advice..


thanks
 
the ON clause determines which rows are joined, and if a match is not found, then in a LEFT OUTER JOIN the columns from that table are set to NULL and the row is returned anyway

so if you are looking for

LEFT OUTER JOIN TabC as TC
ON TC.Col1 = TA.Col1
AND TC.Col2 is null

then there must actually be a row in TabC that meets those conditions

if there isn't, then the TC columns are all set to NULL and the TA row is returned anyway because it's a LEFT OUTER JOIN

note that in that case TC.Col1 (the column being joined) will be NULL too

then after the join has beed decided, only then does the WHERE clause come into play

here's an article that illustrates the difference --
LEFT OUTER JOIN with ON condition or WHERE condition?

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top