Testing some commands of MySQL, I've come across these two comands resulting on the same table.
Command 1:
select sales.relatory_code, sales.date, destiny.exportation_name from sales, destiny where sales.destiny_exportation_code = destiny.destiny_exportation_code;
Command 2:
select sales.relatory_code, sales.date, destiny.exportation_name from sales inner join destiny on sales.destiny_exportation_code = destiny.destiny_exportation_code;
Basically, instead of using two tables on "from" clause and using the "where" clause, i'm just using "inner join". I would like to know what's the main difference between the two commands and if one is better than the other.
1 Answer 1
Command 1 is the SQL-89 standard for joining between tables.
Command 2 is the correct method of writing JOINs as per the ANSI-92 SQL standard (yes, that is 92 as in 1992). Some 23 years later and people still don't want to conform to ANSI-join standards.
Theoretically, there is no difference between the two in terms of performance, it's apparently just a hard habit for people to break and some find it more readable if they're used to writing queries in that way.
There's a few more reasons for why people use the old standard as opposed to the new one in this Stack Overflow post.
I also seemingly keep referring back to Aaron Bertrand's posts (even though this one is written about SQL Server). This one may give you some more information on why you should be using the ANSI-92 Standard style joins.
-
I totally agree that it's better to use the new style (and certainly don't mix the two) but the old-style is still valid SQL, according to the SQL-92 standard. Even according to SQL-2011 standard. It's not wrong per se.ypercubeᵀᴹ– ypercubeᵀᴹ2015年01月14日 16:08:56 +00:00Commented Jan 14, 2015 at 16:08