Log in

View Full Version : JOIN Syntax



james438
11-11-2009, 12:54 AM
Hi,

Just doing a bit of research on MySQL to pass the time. I am reading up on JOIN queries and notice that there are several ways to write the same query. Here are two examples:

Example 1:


SELECT people.name, positions.name FROM test2,people,positions where people.id=test2.ID and positions.id=test2.ID is the same as

SELECT people.name, positions.name FROM test2 JOIN people ON people.id=test2.ID JOIN positions ON positions.id=test2.ID

There are probably more ways to write this, but which is better or are they both pretty much the same?

Example 2:


select * from test1 JOIN test2 where test1.col1=test2.col3
is the same as

select * from test1,test2 where test1.col1=test2.col3
is the same as

select * from test1 JOIN test2 ON test2.col3=test1.col1
is the same as

select * from test1 JOIN test2 ON test1.col1=test2.col3

Which, if any, of the above queries, which all work, should not be used?