DELAPARRA
Index
Color
NL
Category: SQL

LEFT (OUTER) JOIN

Explained by Updated

What is LEFT (OUTER) JOIN?

LEFT (OUTER) JOIN: Keeps every row from the left table; right-table columns are NULL where there is no match. A LEFT JOIN, also called a left outer join, keeps every row from the left table, even when there is no match in the right table. Missing values from the right side become NULL.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about LEFT (OUTER) JOIN

How is LEFT (OUTER) JOIN used in practice?

SELECT users.name, COUNT(orders.id) FROM users LEFT JOIN orders ON ... GROUP BY users.id lists every user with their order count, including users with zero orders. An inner join would drop them.

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

It is also the standard way to find missing data. LEFT JOIN followed by WHERE orders.id IS NULL returns users who have never ordered. One common mistake is putting a condition on the right table in WHERE instead of in the ON clause, which silently turns the left join back into an inner join.

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

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

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with L

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.