What's the difference between these two queries:
SELECT `threads`.`id` AS `threads.id` , `posts`.`id` , `posts`.`content`
FROM `threads`
JOIN `posts` ON `threads`.`id` = `posts`.`thread_id`
And
SELECT `threads`.`id` AS `threads.id` , `posts`.`id` , `posts`.`content`
FROM `threads` , `posts`
WHERE `threads`.`id` = `posts`.`thread_id`
They both return same data.
WHERE
clause filtering result set which is returned by JOIN
, so this is a difference.
As long as you are using INNER JOIN
there is no differences neither performance nor execution plan, in case of any OUTER JOIN
query would produce different execution plan.
Also pay attention to what is said in the MySql online doc:
Generally, you should use the ON clause for conditions that specify how to join tables, and the WHERE clause to restrict which rows you want in the result set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With