SQL · Chapter 18 of 42

RIGHT JOIN

RIGHT JOIN is the mirror of LEFT JOIN — it keeps all rows from the RIGHT table.

Most teams avoid it; simply swap table order and use LEFT JOIN for readability.

When to use

Rarely. Prefer flipping to LEFT JOIN, which reads more naturally.

Example 1 (sql)
SELECT o.id, u.name
FROM orders o
RIGHT JOIN users u ON u.id = o.user_id;
Output
every user; order id or NULL

Same result as LEFT JOIN with tables swapped.

Example 2 (sql)
-- Preferred equivalent:
SELECT o.id, u.name
FROM users u
LEFT JOIN orders o ON o.user_id = u.id;
Output
same result, clearer

Standard practice.

Key points

  • Mirror of LEFT JOIN.
  • Rarely used in modern code.
  • Prefer LEFT JOIN with tables swapped.
  • Not supported in SQLite historically.
💡 Note: SQLite added RIGHT/FULL JOIN only in version 3.39. If you target multiple databases, prefer LEFT JOIN.

📝 Quick Quiz

1. RIGHT JOIN keeps rows from:

2. Best practice today is:

3. Which older DB didn't support RIGHT JOIN?