DELAPARRA
Index
Color
NL
Category: SQL

RIGHT (OUTER) JOIN

Explained by Updated

What is RIGHT (OUTER) JOIN?

RIGHT (OUTER) JOIN: Mirror of LEFT JOIN — keeps every row from the right table. Rare in practice; people just flip the tables. A RIGHT JOIN is the mirror image of a LEFT JOIN. It keeps every row from the right-hand table, and fills in NULL where the left table has no match.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about RIGHT (OUTER) JOIN

How is RIGHT (OUTER) JOIN used in practice?

In practice it is rarely used, because you can get the same result by swapping the tables and writing a LEFT JOIN. Most developers find queries easier to read when the main table comes first and everything else is joined to it from the left.

What should you keep in mind with RIGHT (OUTER) JOIN?

If you see a RIGHT JOIN in existing code, it is not wrong, just less common. Rewriting it as a left join with the tables swapped often makes the query clearer for the next reader. As with any outer join, put conditions on the optional table in the ON clause rather than in WHERE, or the outer join quietly becomes an inner one.

What does an example of RIGHT (OUTER) JOIN look like?

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

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with R

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.