Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 47/ 160
03. Joins & Relational Querying

FULL OUTER JOIN & Data Reconciliation Queries

Reconcile two datasets by keeping unmatched rows from both sides.

IntermediateFULL OUTER JOIN · Reconciliation3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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).

Classify every rowQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  COALESCE(a.id, b.id) AS id,3  CASE4    WHEN b.id IS NULL THEN 'only_ours'5    WHEN a.id IS NULL THEN 'only_provider'6    WHEN a.amount <> b.amount THEN 'amount_mismatch'7    ELSE 'ok'8  END AS status9FROM10  ours a11  FULL OUTER JOIN provider b ON b.id = a.id;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/11
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output4 sample rows
Expected output
idstatus
1001ok
1002amount_mismatch
1003only_ours
1004only_provider

Note: Illustrative reconciliation outcomes for IDs present on one side, both sides with differing amounts, or both sides with matching amounts.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

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.

Filter each side before joining

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

Key takeaway: Filter inside subqueries, not in WHERE, and use IS DISTINCT FROM for comparisons.
Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Inputs

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.

SQL at this stepReadable preview
1(2SELECT …3WHERE day = :d) a, (4SELECT …5WHERE day = :d) b
What to watch at this step
Same
key and scope
Tip: use ← → to move between steps

When 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

FULL OUTER JOIN
Best for: Reconciling two sources in both directions

Strengths: One query shows missing rows on either side and value differences.

Watch out: NULL handling on both sides; not available in MySQL.

LEFT JOIN … IS NULL
Best for: Checking one direction only (rows we have that the other side lacks)

Strengths: Simpler and supported everywhere.

Watch out: Misses rows that exist only on the other side.

EXCEPT (both ways)
Best for: Comparing whole rows between identical-shaped tables

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?
Interview tip: Frame FULL OUTER JOIN around reconciliation. Describing the three outcomes (only left, only right, both) and the COALESCE key shows you've used it for real work.

Knowledge check

Loading quiz

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.

Open SQL Practice →SQL interview Q&A
Previous topic
RIGHT JOIN & When to Rewrite as LEFT JOIN
Next topic
CROSS JOIN (Cartesian Products & Use Cases)