When I should use LEFT/RIGHT JOIN?

What is the difference between left join, right join, and inner join, and when should I use left join instead of right join or inner join

1 Like

There’s a visualisation of different JOIN types here:

(That Venn diagram pops up all over the place, as it seems a useful way of representing how JOIN works).

1 Like

So the core differences between these types of Joins are as follows:

  1. INNER JOIN: Use this when you only want to see the common rows that appear in both tables.
  2. LEFT JOIN: Use this when you want all the data from the left table, even if there’s a match in the right table or not.
  3. RIGHT JOIN: This is the opposite of a LEFT JOIN. Use it when you want all the data from the right table, even if there’s a match in the left table or not.

When choosing a join type, think about the kind of data output you need as your final result, and select the join that best matches your goals. You can check out this website, which helps run sample SQL code and explore the different types of joins: W3Schools SQL Joins.

1 Like