Difference in INNER join and cartesian join in SQL

2019-07-01 23:24发布

问题:

Possible Duplicate:
Difference between Inner Join & Full join

What is the difference between these two, especially within SQL Server 2008 -

select * from table1 t1, table2 t2 where t1.col1 = t2.col1

AND

select * from table1 t1 INNER JOIN table2 t2 ON t1.col1 = t2.col1

回答1:

They are the same.

But consider what your syntax would look like if you wanted to do an INNER JOIN and then also OUTER JOIN to a different table.

It's more consistent to follow the INNER JOIN syntax so that if you need to modify your SQL later, it's easier to do. Plus, consistency allows others to have a better idea of your intent.



回答2:

The first is the old way of writing an inner join, the second is the way it's written after the join command was added to SQL.

As long as both ways are accepted, there is no difference at all in the result. The execution plans for the two queries will be identical.

The old way of writing a join is being phased out, and may be disallowed in certain modes in later versions of SQL Server. It's not in SQL Server 2008.