Outer Joins

This YouTube video was created by Steve Griffith.

The LEFT JOIN and the RIGHT JOIN are often referred to as "Outer Joins" because they will return records outside of the matched records from the other table.

The LEFT JOIN will return all the records from the left table (table 1), and the matched records from the right table (table 2).

Venn Diagram with the inner part colored representing an LEFT JOIN

# Using LEFT JOIN to combine table b and c
SELECT b.name as bname, c.name AS cname, c.id, b.best_friend
FROM b LEFT JOIN c
ON c.id = b.best_friend;

The RIGHT JOIN will return all the records from the right table (table 2), and the matched records from the left table (table 1).

Venn Diagram with the inner part colored representing an RIGHT JOIN

# Using RIGHT JOIN to combine table b and c
SELECT b.name as bname, c.name AS cname, c.id, b.best_friend
FROM b RIGHT JOIN c
ON c.id = b.best_friend;