SQL Tutorial 0/85 lessons ~6 min read Lesson 39
FULL OUTER JOIN
FULL OUTER JOIN keeps unmatched rows from both sides.
Course progress0%
Focus
6 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
FULL OUTER JOIN keeps unmatched rows from both sides. Used for reconciliation: 'show me every user and every order, marking which side is missing.'
Understanding the topic
Core concepts to understand:
FROM a FULL OUTER JOIN b ON ....- NULLs on the side with no match.
- Find mismatches:
WHERE a.id IS NULL OR b.id IS NULL. - MySQL doesn't support it directly — emulate with LEFT JOIN UNION RIGHT JOIN.
- Heavier than INNER/LEFT — use only when needed.
Syntax reference
Visual workflow / architecture:
bash
users orders1 ──── matches ──── 1, 22 ──── matches ──── 33 ──── (no order)──── 99 (orphan order)FULL OUTER → 4 rows including orphans on both sides
Syntax Pattern
SELECT <cols>
FROM <a> [AS a]
FULL OUTER JOIN <b> [AS b]
ON <a.key> = <b.key>;FULL OUTER JOINKeeps unmatched rows from BOTH sides — NULLs fill the gaps.reconciliationPerfect for 'what's missing on either side?' audits.
Live Example
sql
SELECT u.name, o.amountFROM users uFULL OUTER JOIN orders o ON o.user_id = u.id;
users + orders
| u.id | u.name | o.id | o.amount |
|---|---|---|---|
| 1 | Ana | 101 | 50 |
| 2 | Leo | — | — |
| — | — | 103 | 70 |
runs
joined
| name | amount |
|---|---|
| Ana | 50 |
| Leo | NULL |
| NULL | 70 |
Both orphan users and orphan orders are preserved.
Real-world use
Daily reconciliation jobs ('our records vs partner records') and data migration audits use FULL OUTER JOIN heavily.
Best practices
- Use only when both sides matter.
- MySQL: emulate or use Postgres for analytics.
- Always show which side was missing in the result.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. Full outer vs inner vs left.
- Q2. Emulating FULL JOIN in MySQL.
- Q3. Use case for FULL JOIN.
- Q4. Find mismatches on either side.
- Q5. Performance considerations.
Ready to mark this lesson complete?Track your journey across the entire course.