Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query JOIN Performance

I wanted to know what is better performance-wise: to put the conditions in the JOIN? (x JOIN y on x.hi = y.hi AND ....) or maybe to put it under the WHERE, and leave the JOIN only with the crossing condition.

thanks folks

like image 633
Himberjack Avatar asked Aug 17 '26 23:08

Himberjack


2 Answers

This will depend on the query optimisation engine and how it breaks the query down into its logical query operators.

With MS SQL Server you can view the execution plan but normally there is no difference as the optimiser will see both ways as equivalent.

like image 150
Johnno Nolan Avatar answered Aug 19 '26 15:08

Johnno Nolan


There is a similar question on StackOverflow here.

It's largely just a matter of which syntax you prefer. My understanding is that the SQL optimizer should be able to evaluate them with little difference in performance.

like image 45
Bernard Dy Avatar answered Aug 19 '26 15:08

Bernard Dy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!