Skip to content

RIGHT JOIN

Medium — good to knowDatabase

ELI5 — The Vibe Check

RIGHT JOIN is LEFT JOIN's mirror image — it returns all rows from the right table, and matching rows from the left. Nobody uses RIGHT JOIN in practice because you can always rewrite it as a LEFT JOIN by swapping the table order. But it exists.

Real Talk

RIGHT JOIN (or RIGHT OUTER JOIN) returns all rows from the right (second) table regardless of whether a matching row exists in the left table. It is functionally equivalent to LEFT JOIN with the tables swapped. Most developers prefer LEFT JOIN for consistency.

Show Me The Code

-- Equivalent to swapping tables in a LEFT JOIN
SELECT u.name, o.total
FROM orders o
RIGHT JOIN users u ON o.user_id = u.id;

When You'll Hear This

"RIGHT JOIN works but most developers just flip the tables and use LEFT JOIN instead."

Made with passive-aggressive love by manoga.digital. Powered by Claude.