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

JOINs with delayed ON 1

Status
Not open for further replies.

JohnDTampaBay

Programmer
Jul 12, 2002
986
US
I have inherited some T-SQL code and I keep running into JOINs with delayed ONs. Much of the code was generated by the graphical Query Designer. I found this example in BOL FROM clause -> FROM clause (described):
< joined_table >

Is a result set that is the product of two or more tables, for example:

SELECT *
FROM tab1 LEFT OUTER JOIN tab2 ON tab1.c3 = tab2.c3
RIGHT OUTER JOIN tab3 LEFT OUTER JOIN tab4
ON tab3.c1 = tab4.c1
ON tab2.c3 = tab4.c3

For multiple CROSS joins, use parentheses to change the natural order of the joins.
Can't this be written as
SELECT *
FROM tab1
LEFT OUTER JOIN tab2
ON tab1.c3 = tab2.c3
LEFT OUTER JOIN tab4
ON tab2.c3 = tab4.c3
RIGHT OUTER JOIN tab3
ON tab3.c1 = tab4.c1
What's the purpose of the delayed ON criteria between tab2 and tab4 in the BOL example? What am I missing?

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
yes, it can be written like that, and i don't know what the purpose of that delayed syntax might be, it just looks wrong, somehow

but i will tell you one thing, anybody who writes a four-table join like that, by mixing LEFT OUTER JOINs with a RIGHT OUTER JOIN, deserves to be confused

r937.com | rudy.ca
 
Thanks, r937. I thought it was just me, but now I feel vindicated. I would never mix LEFT and RIGHT OUTER JOINs either.

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top