SQL join : impact on Performance
This article is to record my learning on different join syntax on SQL and the performance how we select these.
The join
syntax can obtain data from multiple tables, and when it comes to inner join
, left join
and right join
to obtain data from to relational tables, use inner join first. If under specific circumstances we need to left join
, keep the left table as small as possible.
- Inner join only retain the completely matching result sets in the two tables, so will have better performance.
- Left join will return all rows from the left table, even if there are no matching records in the right table
- Similarly, right join will return all rows from the right table, even if there are no matching records in the left table
Through the example of Left join, if we use SQL query, remember one of the principles to improve SQL performance is a table with less data table better drives a table with more data.