Answer the question
In order to leave comments, you need to log in
What is the difference between the 2 queries?
Help me understand what the second request is doing.
The first, as I understand it, displays all matches of id tables a and b.
The second one I can't understand.
1.
2.SELECT * FROM a, b WHERE a.id=b.a_id;
SELECT * FROM a JOIN b ON a.id=b.a_id;
Answer the question
In order to leave comments, you need to log in
The main difference is that the former uses the Cartesian product with selection, which has long been considered bad practice.
Otherwise , these two queries are absolutely equivalent up to the order of execution. The "comma" operation has a lower precedence than the JOIN operation, i.e. the first query does an implicit STRAIGHT_JOIN. And if the DBMS can't give a damn about this, the first query may generate a suboptimal execution plan even with up-to-date data statistics.
In more complex queries, the use of a comma, especially in combination with JOIN, can generally break the query completely, up to syntactic incorrectness. Therefore, it is strongly recommended to use CROSS JOIN instead of a comma.
The result of these queries is identical, however you should use JOIN following modern SQL standards.
Related article
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question