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 NULLSame 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, clearerStandard 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.
