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

Opinions on join syntax? 1

Status
Not open for further replies.

mowog74

Programmer
May 29, 2001
15
US
I typically use the JOIN keyword when joining tables, e.g.:

SELECT [...]
FROM Orders o
INNER JOIN OrderStatus os ON o_OrderStatusId = os.Id
WHERE o.Id = 5


But lately I've been seeing (esp. in Books Online) syntax like:

SELECT [...]
FROM Orders o, OrderStatus os
WHERE o_OrderStatusId = os.Id
AND o.Id = 5

Is there any functional difference between the two methods? Is one preferred? I like the first method for readability, but I get the impression that maybe the second method is more ANSI compliant. Any thoughts?
 
Check the article on Microsoft's SQL Web Site explaining why the ANSI style joins are preferred.


It is ironic, that MS is moving toward ANSI style but the documentation is laced with old style joins. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks Terry. Also, I think I had it backwards--after reading the article you suggested and others it looks like the first syntax in my original post (using the JOIN keyword) is ANSI style. Thanks for straightening me out!
 
You should use the ansi joins for production code. I have to admit that when I am doing a quick adhoc query from query analyser I frequently use the where style, it just seems faster to type.
 

I failed to note that I prefer the ANSI syntax for at least two reasons.

1) It separates the JOIN criteria from the WHERE criteria in the query.
2) It shows clearly the relatiobships between the tables and views in the query. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
I would add that ANSI style joins can be faster than "natural" joins (doing joins using only the WHERE clause). Presumably this is because the specialized join statements allow the query processor to do optimization that it otherwise cannot.

- Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top