Academic Block

SQL FULL JOIN Get Certified

Learn how to combine every row from two tables using FULL JOIN (also called FULL OUTER JOIN) and how to write a reliable SQLite-compatible version with LEFT JOIN + UNION.

What is FULL JOIN?

A FULL JOIN returns all matching rows and all non-matching rows from both tables. When a row has no match in the other table, the missing side is filled with NULL.

In simple terms, FULL JOIN is the combination of LEFT JOIN and RIGHT JOIN: nothing is dropped from either side.

Important: FULL JOIN in SQLite

Newer versions of SQLite support FULL OUTER JOIN, but support is not universal across all online SQLite engines. For maximum reliability the interactive examples below use the classic pattern:

LEFT JOIN of table A to table B
UNION
LEFT JOIN of table B to table A where the A side is NULL

This produces exactly the same result as a true FULL JOIN and works everywhere.

Basic FULL JOIN (SQLite-Compatible)

Every product that exists in either the online catalogue or the store catalogue appears in the result. Matching products are combined; products that exist in only one table show NULL on the other side.

What this code does: Laptop exists only online, Smartwatch exists only in the store, and Tablet / Camera exist in both. The query returns 4 rows covering every product from both tables.

WITH online_products(product_id, product_name) AS (
  VALUES
    (1, 'Laptop'),
    (2, 'Tablet'),
    (3, 'Camera')
),
store_products(product_id, product_name) AS (
  VALUES
    (2, 'Tablet'),
    (3, 'Camera'),
    (4, 'Smartwatch')
)
SELECT
  o.product_id   AS online_id,
  o.product_name AS online_product,
  s.product_id   AS store_id,
  s.product_name AS store_product
FROM online_products AS o
LEFT JOIN store_products AS s
  ON o.product_id = s.product_id
UNION
SELECT
  o.product_id,
  o.product_name,
  s.product_id,
  s.product_name
FROM store_products AS s
LEFT JOIN online_products AS o
  ON s.product_id = o.product_id
WHERE o.product_id IS NULL
ORDER BY online_id, store_id;

FULL JOIN with Employee Records

When two systems contain partially overlapping employee lists, a FULL JOIN shows the complete picture: people who exist in both systems, only in A, or only in B.

What this code does: Aarav exists only in company A, Riya only in company B, and Meera / Kabir exist in both. The query returns 4 rows.

WITH company_a(employee_id, employee_name) AS (
  VALUES
    (101, 'Aarav'),
    (102, 'Meera'),
    (103, 'Kabir')
),
company_b(employee_id, employee_name) AS (
  VALUES
    (102, 'Meera'),
    (103, 'Kabir'),
    (104, 'Riya')
)
SELECT
  a.employee_id   AS company_a_id,
  a.employee_name AS company_a_name,
  b.employee_id   AS company_b_id,
  b.employee_name AS company_b_name
FROM company_a AS a
LEFT JOIN company_b AS b
  ON a.employee_id = b.employee_id
UNION
SELECT
  a.employee_id,
  a.employee_name,
  b.employee_id,
  b.employee_name
FROM company_b AS b
LEFT JOIN company_a AS a
  ON b.employee_id = a.employee_id
WHERE a.employee_id IS NULL
ORDER BY company_a_id, company_b_id;

Finding Records That Exist in Only One Table

After building a FULL JOIN result you can filter it to keep only the unmatched rows. This is a common way to find differences between two data sources.

What this code does: Returns only the customers who appear in the website list but not the app list, or in the app list but not the website list. Nisha and Dev are the unmatched customers.

WITH website_customers(customer_id, customer_name) AS (
  VALUES
    (1, 'Nisha'),
    (2, 'Rohan'),
    (3, 'Tara')
),
app_customers(customer_id, customer_name) AS (
  VALUES
    (2, 'Rohan'),
    (3, 'Tara'),
    (4, 'Dev')
)
SELECT
  w.customer_id   AS website_id,
  w.customer_name AS website_name,
  a.customer_id   AS app_id,
  a.customer_name AS app_name
FROM website_customers AS w
LEFT JOIN app_customers AS a
  ON w.customer_id = a.customer_id
WHERE a.customer_id IS NULL
UNION
SELECT
  w.customer_id,
  w.customer_name,
  a.customer_id,
  a.customer_name
FROM app_customers AS a
LEFT JOIN website_customers AS w
  ON a.customer_id = w.customer_id
WHERE w.customer_id IS NULL
ORDER BY website_id, app_id;

FULL JOIN with Different Numbers of Rows

The two tables do not need the same number of rows. FULL JOIN simply keeps everything from both sides.

What this code does: Physics and Biology exist only in the morning list, History and Geography only in the evening list, and Chemistry exists in both. The query returns 5 rows.

WITH morning_classes(class_id, class_name) AS (
  VALUES
    (1, 'Physics'),
    (2, 'Chemistry'),
    (3, 'Biology')
),
evening_classes(class_id, class_name) AS (
  VALUES
    (2, 'Chemistry'),
    (4, 'History'),
    (5, 'Geography')
)
SELECT
  m.class_id   AS morning_id,
  m.class_name AS morning_class,
  e.class_id   AS evening_id,
  e.class_name AS evening_class
FROM morning_classes AS m
LEFT JOIN evening_classes AS e
  ON m.class_id = e.class_id
UNION
SELECT
  m.class_id,
  m.class_name,
  e.class_id,
  e.class_name
FROM evening_classes AS e
LEFT JOIN morning_classes AS m
  ON e.class_id = m.class_id
WHERE m.class_id IS NULL
ORDER BY morning_id, evening_id;

FULL JOIN with Sales Data

Comparing two monthly sales tables is a typical real-world use of FULL JOIN.

What this code does: Keyboard appears only in January, Webcam only in February, and Mouse / Monitor appear in both months (with their respective amounts). The query returns 4 rows.

WITH january_sales(product_id, product_name, amount) AS (
  VALUES
    (1, 'Keyboard', 1200),
    (2, 'Mouse', 800),
    (3, 'Monitor', 2500)
),
february_sales(product_id, product_name, amount) AS (
  VALUES
    (2, 'Mouse', 950),
    (3, 'Monitor', 2800),
    (4, 'Webcam', 1100)
)
SELECT
  j.product_name AS january_product,
  j.amount       AS january_amount,
  f.product_name AS february_product,
  f.amount       AS february_amount
FROM january_sales AS j
LEFT JOIN february_sales AS f
  ON j.product_id = f.product_id
UNION
SELECT
  j.product_name,
  j.amount,
  f.product_name,
  f.amount
FROM february_sales AS f
LEFT JOIN january_sales AS j
  ON f.product_id = j.product_id
WHERE j.product_id IS NULL
ORDER BY january_product, february_product;

Native FULL OUTER JOIN (Modern SQLite)

If your SQLite environment supports the modern syntax you can write a true FULL OUTER JOIN directly. The result is identical to the UNION pattern used above.

What this code does: Notebook exists only on the left, Marker only on the right, and Pen / Folder exist on both sides. The query returns 4 rows.

WITH left_items(item_id, item_name) AS (
  VALUES
    (1, 'Notebook'),
    (2, 'Pen'),
    (3, 'Folder')
),
right_items(item_id, item_name) AS (
  VALUES
    (2, 'Pen'),
    (3, 'Folder'),
    (4, 'Marker')
)
SELECT
  l.item_id   AS left_id,
  l.item_name AS left_item,
  r.item_id   AS right_id,
  r.item_name AS right_item
FROM left_items AS l
FULL OUTER JOIN right_items AS r
  ON l.item_id = r.item_id
ORDER BY left_id, right_id;

FULL JOIN vs Other JOINs

JOIN Type
Matching Rows
Unmatched Left
Unmatched Right
INNER JOIN
Yes
No
No
LEFT JOIN
Yes
Yes
No
RIGHT JOIN
Yes
No
Yes
FULL JOIN
Yes
Yes
Yes

Common Uses of FULL JOIN

  • Compare two data sources that may contain different records.
  • Find rows that exist in only one of the two tables.
  • Combine complete datasets while preserving every unmatched row.
  • Reconcile customer, product, employee or sales lists from different systems.
  • Identify differences between two versions of the same dataset.

Best Practices

  • Prefer the LEFT JOIN + UNION pattern when you need maximum SQLite compatibility.
  • Always join on a reliable key column in the ON clause.
  • Use IS NULL filters when you only want the unmatched rows.
  • Use clear table aliases so the longer UNION queries stay readable.
  • Consider COALESCE when you want to replace NULL values with defaults.
  • Test both the UNION pattern and (if available) native FULL OUTER JOIN to confirm identical results.

A FULL JOIN returns every row from both tables. Matching rows are combined; unmatched rows appear with NULL on the missing side. Because native FULL OUTER JOIN support varies in SQLite, the interactive examples use the reliable LEFT JOIN + UNION technique. Click Test My Code on any example to run it live, or Code Explanation to walk through the query block by block.

Ctrl + Enter to run code in the editor Esc to close the editor

🧪 Test Your SQL Code

Edit the SQL code on the left and click “Run Code” to see the result on the right.

📝 SQL Code
👁️ Preview (query result)

Click “Run Code” to see the result here.