Start studying
Module 5 · SQL Module contents
Module 5  ·  Card 10 / 14intermediate

Outer Joins

Outer joins combine tables while preserving rows from one or both sides that have no matching records in the other table.

A LEFT JOIN keeps every row from the left table, filling in NULL for all columns from the right table whenever a match is absent.

A RIGHT JOIN does the reverse, keeping all rows from the right table and filling in NULLs for non-matching left columns.

A FULL OUTER JOIN retains all records from both tables, filling in NULLs whenever a match does not exist on either side.

Outer joins are indispensable for finding inactive users, missing inventory links, and unfulfilled customer transactions.

Learn in depth ↓
Module 05 · SQL · 14 concepts
In depth  /  15 lines

Outer Joins, in more detail

Outer joins extend relational joins by preserving rows that fail to find matching partners in the opposite table.

In a LEFT OUTER JOIN, all rows from the left table are retained in the result set regardless of whether a match exists.

For left rows without matching right records, the database engine populates all right-table columns with NULL values.

Conversely, a RIGHT OUTER JOIN preserves all rows from the right table, populating missing left columns with NULLs.

Most practitioners prefer LEFT JOIN exclusively, reordering table references to make queries read consistently from left to right.

A FULL OUTER JOIN retains all rows from both tables, filling in NULLs whenever a match is missing on either side.

Outer joins are essential for identifying unmatched records, such as finding customers who have never placed an order.

To isolate unmatched records, perform a LEFT JOIN and add a filter in the WHERE clause checking where right key IS NULL.

This anti-join pattern is a staple technique for data quality auditing and customer churn investigations.

A common trap occurs when filtering right-table columns in the WHERE clause of a LEFT JOIN query.

If the WHERE clause requires a right-table column to equal a value, it inadvertently discards rows where that column is NULL.

This mistake converts the LEFT JOIN into an accidental INNER JOIN, stripping out the very unmatched rows intended to be kept.

To preserve outer join behaviour while filtering the right table, the condition must be placed in the ON clause instead.

Conditions placed in the ON clause restrict matching before the outer join preserves unmatched rows.

Analysts should always inspect outer join results for unintended NULLs before passing data into downstream modelling pipelines.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A manager wants a report of all registered customers and their purchases, including customers who have never bought anything. Which join is required?
SQL

14 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close