Python SQL RIGHT JOIN: Preserving Unmatched Right Rows
The `RIGHT JOIN` (or `RIGHT OUTER JOIN`) returns ALL records from the right table, and the matched records from the left table. Any unmatched left-side rows are padded with `NULL`. In modern practice, developers almost exclusively write `LEFT JOIN` by swapping table order for standard readability.
"`RIGHT JOIN` is simply looking at a `LEFT JOIN` through a mirror: every row of Table B is kept, and missing matches from Table A show up as blank."
Deep Dive: How It Works
Equivalence: `SELECT * FROM A RIGHT JOIN B ON A.id = B.a_id` is 100% mathematically and functionally identical to `SELECT * FROM B LEFT JOIN A ON A.id = B.a_id`.
Engine Support: While supported in PostgreSQL, MySQL, and SQL Server, SQLite historically omits RIGHT JOIN (supported only in SQLite 3.39+).
Code Style Convention: Engineering teams standardize on `LEFT JOIN` so that query reading flow progresses consistently from left to right.
Syntax Blueprint
SELECT o.id, c.name FROM orders AS o RIGHT JOIN customers AS c ON o.customer_id = c.id; -- Recommended equivalent LEFT JOIN: SELECT o.id, c.name FROM customers AS c LEFT JOIN orders AS o ON c.id = o.customer_id;
RIGHT JOIN preserves all rows from the right table; identical to swapping LEFT JOIN table order.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Mixing LEFT JOIN and RIGHT JOIN arbitrarily in a 5-table query.Why it happens: Creates complex, confusing join dependencies that are hard to debug.
How to fix: Standardize on `LEFT JOIN` throughout the entire query.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Preserve Master Table with Outer Join
Select `c.name`, `p.title` from `categories c LEFT JOIN products p ON c.id = p.cat_id` ordered by `c.id`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.