Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in INNER join and cartesian join in SQL Server [duplicate]

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
like image 617
cherry Avatar asked Oct 28 '25 14:10

cherry


2 Answers

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.

like image 97
David Hoerster Avatar answered Oct 31 '25 05:10

David Hoerster


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.

like image 31
Guffa Avatar answered Oct 31 '25 04:10

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!