0PricingLogin
SQL Academy · Lesson

LEFT/RIGHT JOIN and OUTER Joins

Use LEFT JOIN to keep unmatched rows, understand RIGHT and FULL OUTER joins, and detect missing data with WHERE x IS NULL.

LEFT JOIN: Keep All Left Rows

LEFT JOIN returns every row from the left table, with matched right-side columns or NULL when there's no match.

SELECT u.id, u.email, o.id AS order_id
FROM users u
LEFT JOIN orders o ON o.user_id = u.id;

-- Users without orders still appear, with order_id = NULL.

RIGHT JOIN

The mirror of LEFT JOIN — keep all RIGHT rows. Most people just rewrite RIGHT joins as LEFT for readability:

SELECT u.id, u.email, o.id
FROM orders o
RIGHT JOIN users u ON u.id = o.user_id;

-- Equivalent to LEFT JOIN with sides swapped:
SELECT u.id, u.email, o.id
FROM users u
LEFT JOIN orders o ON o.user_id = u.id;

All lessons in this course

  1. Why Joins (Relational Model Recap)
  2. INNER JOIN Mechanics
  3. LEFT/RIGHT JOIN and OUTER Joins
  4. Self-Joins and Aliases
← Back to SQL Academy