Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the two SQL join notations?

SQL 1: select * from t1 join t2 on t1.f1 = t2.f2

SQL 2: select * from t1,t2 where t1.f1 = t2.f2

The results that they return are same. Are there any differences between them? For example, in how the DBMS runs them, or in the query plan?

like image 393
SleeplessKnight Avatar asked Nov 24 '11 01:11

SleeplessKnight


3 Answers

There is no operational difference between the two queries.

However, the explicit join notation is the better style to learn and use; leave the other for (as yet unchanged) legacy code.

like image 191
Jonathan Leffler Avatar answered Nov 06 '22 03:11

Jonathan Leffler


One is old style and one is new (ANSI) style. The main reason that I've found why you would want to use the new style is for standard support of outer joins. With the old style, outer joins are vendor-specific. New style has it standard:

select * from t1 left outer join t2 on t1.f1 = t2.f2

In your example, SQL 1 is the new and SQL 2 is the old style, btw.

like image 6
Jake Feasel Avatar answered Nov 06 '22 03:11

Jake Feasel


Basically, there are no difference between the two queries in operation.

However, both have same execution plan and have same cost that mean both query take equal time to execute(same performance).

Use of join operator is a modern way.

like image 1
Elias Hossain Avatar answered Nov 06 '22 03:11

Elias Hossain