Let A and B be two tables in a database schema. A and B are related by a many-to-one relationship. There exists many B’s for each A, and B has a foreign key column a_id. Both tables have a primary key column id.
Which of the following two queries performs better for large data sets in A and B?
SELECT A.* FROM A,B WHERE A.id = B.a_id
or
SELECT A.* FROM A INNER JOIN B ON A.id = B.a_id
Or are they equivalent?
They are equivalent for all
4major database systems:Oracle,SQL Server,MySQL,PostgreSQL.Using
JOINsyntax (to be more exact, usingSTRAIGHT_JOINinstead ofJOIN) will help to enforce the join order you need inMySQL.See this answer for details:
It’s also generally considered more clean and readable to use the
JOINsyntax.Though I’m grown on
Oraclecode samples which generally use theWHEREsyntax.