I’ve heard this question a lot, but never thought to blog about the answer. “Is there a performance difference between putting the JOIN conditions in the ON clause or the WHERE clause in MySQL?”
No, there’s no difference. The following queries are algebraically equivalent inside MySQL and will have the same execution plan.
|
1 |
<br>SELECT * FROM A, B WHERE A.ID = B.ID;<br><br>SELECT * FROM A JOIN B ON A.ID = B.ID;<br><br>SELECT * FROM A JOIN B USING(ID);<br> |
Personally, I prefer to stay away from “comma joins” because a) the ANSI join syntax is more expressive and you’re going to use it anyway for LEFT JOIN, and mixing styles is asking for trouble, so you might as well just use one style; b) I think ANSI style is clearer. But that’s just personal preference.