0

SQL Joins

MS SQL

A post on <cfsilence> today got me think of joins and the right vs wrong way to do things.

When doing an SQL inner join is it best to have something like

SELECT    a.someThing1,a.someThing2
              b.someThing1,b.someThing2
FROM      someTable1 a INNER JOIN       
              someTable2 b ON a.someKey1 = b.someKey1       

or something like this

SELECT    a.someThing1,a.someThing2
              b.someThing1,b.someThing2
FROM      someTable1 a,
              someTable2 b
WHERE    a.someKey1 = b.someKey1

Notice the join is in the from statment in first example vs the where statement in the second example.   Is there a difference betweent the two?  Is one better than the other?  How do you do it?  How do you roll?

Good Day!
Ryan

tags:
MS SQL
fro said:
 
I prefer using the keywords because it makes it easier for me to identify what is going on quickly. Also, it's ANSII standard (I think). So you "should" be able to use the same SQL block (as above anyway) and run it on any DB. Personally, I write my joins this way.

SELECT a.something1, a.something2, b.something1, b.something2
FROM sometable1 a
INNER JOIN sometable2 b
ON a.somekey = b.somekey
 
posted 1082 days ago
Add Comment Reply to: this comment OR this thread
 
todd sharp said:
 
I think you're right about the standard Fro. Even so, it's terribly confusing to me to see it the first way - maybe because I was taught the second way?
 
posted 1082 days ago
Add Comment Reply to: this comment OR this thread
 
Rob Wilkerson said:
 
It is the standard and, as I recall, it's an important standard because of ambiguities created when doing outer joins within the WHERE clause. There's a good explanation of those ambiguities that I've read several times before, but I don't seem to be able to find it right now.

This was a big flap in the Oracle world around version 8i because at that time Oracle didn't support the (LEFT|RIGHT)? JOIN syntax. A quick Google of "oracle outer join syntax" may net some usefule information for those who may be interested.
 
posted 1067 days ago
Add Comment Reply to: this comment OR this thread
 

Search