FULL OUTER JOIN & Data Reconciliation Queries
Reconcile two datasets by keeping unmatched rows from both sides.
In plain words
Keep everyone from both lists. Match them up where you can, and leave blanks where someone appears on only one list.
Think of it like…
Comparing two guest lists, the RSVPs and the people who actually showed up: you want everyone who appears on either list, and to see who RSVP'd but didn't come, and who came without RSVPing.
Where you’ve seen it
Reconciling payments: SELECT COALESCE(a.payment_id, b.payment_id) AS payment_id, a.amount AS ours, b.amount AS provider FROM our_payments a FULL OUTER JOIN provider_payments b ON b.payment_id = a.payment_id WHERE a.payment_id IS NULL OR b.payment_id IS NULL OR a.amount <> b.amount;
Words you’ll hear
- Both-side NULLs
- Unmatched rows have NULLs for whichever table they're missing from.
- Reconciliation
- Comparing two datasets to find rows missing from either side or with different values.
- COALESCE(a.key, b.key)
- The standard way to show one key column for every output row.
- Emulation
- MySQL has no FULL OUTER JOIN; combine a LEFT JOIN and a RIGHT JOIN with UNION.
Visual diagram
Theory & example queries
How the result is built
The database first produces the matched pairs (like an INNER JOIN), then adds every left row that matched nothing (right columns NULL) and every right row that matched nothing (left columns NULL). The result has at least as many rows as the larger table.
Because either side's key can be NULL, show the key with COALESCE(a.id, b.id), and classify rows with a.id IS NULL (only in b) and b.id IS NULL (only in a).
SELECT COALESCE(a.id, b.id) AS id, CASE WHEN b.id IS NULL THEN 'only_ours' WHEN a.id IS NULL THEN 'only_provider' WHEN a.amount <> b.amount THEN 'amount_mismatch' ELSE 'ok' END AS statusFROM ours a FULL OUTER JOIN provider b ON b.id = a.id;PostgreSQL is the lesson baseline unless noted otherwise.
Calculate the selected expressions and return the requested output columns.
Expected output4 sample rows
| id | status |
|---|---|
| 1001 | ok |
| 1002 | amount_mismatch |
| 1003 | only_ours |
| 1004 | only_provider |
Note: Illustrative reconciliation outcomes for IDs present on one side, both sides with differing amounts, or both sides with matching amounts.
Key takeaway: Matched pairs plus unmatched rows from both sides.
Pitfalls and emulating it
A WHERE condition on one table's column (WHERE a.status = 'paid') removes the rows where that side is NULL, quietly turning the FULL JOIN into a LEFT or RIGHT JOIN. Filter each side in a subquery before joining instead.
MySQL doesn't support FULL OUTER JOIN. Emulate it with a LEFT JOIN, plus the right-side rows that have no match: SELECT … FROM a LEFT JOIN b ON … UNION ALL SELECT … FROM a RIGHT JOIN b ON … WHERE a.id IS NULL. Also note that comparing values with <> misses differences where one side is NULL; use IS DISTINCT FROM.
FROM (SELECT * FROM ours WHERE day = '2026-11-18') a FULL OUTER JOIN (SELECT * FROM provider WHERE day = '2026-11-18') b ON b.id = a.id
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Line up the two sources
Make sure both sides use the same key and the same scope (same day, same account). Filter each in a subquery.
(SELECT …WHERE day = :d) a, (SELECT …WHERE day = :d) bWhen to use it & trade-offs
What it is
FULL OUTER JOIN returns every row from both tables. Rows that match are combined; rows with no match on the other side still appear, with NULLs in the other table's columns. It's LEFT JOIN and RIGHT JOIN at the same time.
Why it matters: Its main job is reconciliation: comparing two sources that should agree (payments in your database vs the payment provider's report, or yesterday's snapshot vs today's) and listing what's missing on each side. Data engineering and finance teams use it constantly, and it's a standard "types of joins" interview question.
When to reach for it
- Reconciling payments, invoices or inventory between two systems
- Comparing two snapshots of a table
- Merging two partial datasets where either side may have extra keys
When to avoid or be careful
- WHERE filters on one side's columns after the join
- Comparing values with <> when either side can be NULL
- FULL OUTER JOIN where a LEFT JOIN would answer the question
FULL OUTER JOIN vs LEFT JOIN vs EXCEPT
Strengths: One query shows missing rows on either side and value differences.
Watch out: NULL handling on both sides; not available in MySQL.
Strengths: Simpler and supported everywhere.
Watch out: Misses rows that exist only on the other side.
Strengths: Short, and treats NULLs as equal.
Watch out: Doesn't show which column differs; two queries for two directions.
Interview signals & numbers to know
When this topic comes up
- “Find records missing from either system”
- “Reconcile our data with the provider's report”
- “Compare yesterday's snapshot with today's”
- Types of joins
- “FULL JOIN in MySQL”
Benchmarks & rules of thumb
- 3
- row types: matched, left-only, right-only
- ≥ max(|A|, |B|)
- result size for one-to-one keys
- 0
- FULL JOIN support in MySQL
Common mistakes & follow-ups
Common interview mistakes
- Selecting a.id as the key and getting NULL for every row that exists only on the right.
- Adding WHERE a.status = 'paid' and losing all right-only rows.
- Using a.amount <> b.amount and missing rows where one amount is NULL.
Likely interviewer follow-ups
- How would you emulate a FULL OUTER JOIN in MySQL?
- How would you list payments that exist in only one of two systems, and those whose amounts differ?
- When would EXCEPT be a better tool than a FULL OUTER JOIN?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply FULL OUTER JOIN & Data Reconciliation Queries with hands-on SQL practice and interview Q&A.