Full Outer Join

SQL · Joining Multiple Tables

Theory

FULL OUTER JOIN keeps every row from both tables. Matched pairs are combined as usual, left rows with no match get NULLs on the right, and right rows with no match get NULLs on the left. You can think of it as LEFT JOIN plus the unmatched rows a RIGHT JOIN would add.

It is the natural tool for comparing two lists or reconciling two systems: rows present in both, only in A and only in B all show up, and you tell them apart with IS NULL checks on the key columns. PostgreSQL, SQL Server, Oracle, Snowflake and recent SQLite support it. MySQL does not, so there you emulate it with a LEFT JOIN UNION a RIGHT JOIN (or a LEFT JOIN plus an anti-join).

Why we use it

Reconciliation tasks (source vs target, this month vs last month, system A vs system B) need to see everything on both sides, including what is missing from either one. FULL OUTER JOIN shows all of it in one result.

When to use it

Use FULL OUTER JOIN to compare two datasets or merge lists where either side may have extra rows. If only one side must be kept completely, use LEFT JOIN. On MySQL, emulate it with UNION.

How it works

  1. Match rows from both tables on the ON condition
  2. Output combined rows for every matched pair
  3. Any left rows left unmatched? Yes: Output them with NULLs on the right. No: Skip this step.
  4. Any right rows left unmatched? Yes: Output them with NULLs on the left. No: Skip this step.
  5. Return everything from both sides

Syntax

SELECT columns
FROM t1
FULL OUTER JOIN t2 ON t1.id = t2.t1_id;

Example

SELECT e.name, d.department_name
FROM employees e
FULL OUTER JOIN departments d ON e.dept_id = d.id;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic