Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between INNER JOIN and , COMMA [duplicate]

Tags:

sql

I get the same result in both queries below and same execution plan, any difference? or it is just how I prefer to write my query?

SELECT PS.StepID,PR.ProgramID FROM ProgramSteps PS, Programs PR
WHERE PS.ProgramID = PR.ProgramID

SELECT PS.StepID,PR.ProgramID FROM ProgramSteps PS
INNER JOIN Programs PR ON PS.ProgramID = PR.ProgramID
like image 427
Victor Hugo Terceros Avatar asked Aug 31 '17 14:08

Victor Hugo Terceros


1 Answers

One difference is that the first option hides the intent by expressing the join condition in the where clause.

The second option, where the join condition is written out is more clear for the user reading the query. It shows the exact intent of the query.

As far as performance or any other difference, there shouldn't be any. Both queries should return the exact same result and perform the same under most RDBMS.

And as @Tim Biegeleisen says in the comments:

the comma version is deprecated as of the ANSI-92 SQL standard

like image 192
myst1c Avatar answered Sep 30 '22 16:09

myst1c