Checking your session…
Module 10: SQL Joins

10.5 FULL JOIN

Level: 10 | Version: v1.1 | Author: Meptrasoft

Overview

FULL JOIN returns all rows from both tables.

  • Matching rows are combined.
  • Unmatched left rows remain with NULL on the right.
  • Unmatched right rows remain with NULL on the left.
TEXT
LEFT TABLE
     +
RIGHT TABLE
     ↓
FULL JOIN
     ↓
ALL ROWS FROM BOTH

FULL JOIN → Keep everything from both tables.

FULL JOIN — Keep All Rows from both tables
Figure 1: FULL JOIN keeps all rows from both tables and uses NULL where a matching row does not exist.

Practice Tables

This topic reuses the customers and orders tables from 10.2.

In the original data:

  • Some customers have no orders.
  • Every existing order has a matching customer.

For example:

TEXT
Anjali Verma → no order
Rahul Das    → no order
Divya Nair   → no order

Basic FULL JOIN

SQL
SELECT c.customer_name, o.order_id
FROM customers c
FULL JOIN orders o
    ON c.customer_id = o.customer_id;

A FULL JOIN keeps:

TEXT
Matching customers + orders
     +
Customers without orders
     +
Orders without customers

Understanding the Result

Suppose:

TEXT
Customer 1 → Order 101
Customer 2 → Order 102
Customer 3 → No order
Order 103  → No customer

The result is:

customer_name order_id
Customer 1 101
Customer 2 102
Customer 3 NULL
NULL 103

The unmatched row gets NULL on the side where no match exists.

FULL JOIN preserves unmatched rows from both sides.


FULL JOIN vs Other Joins

TEXT
INNER JOIN → MATCHING ONLY

LEFT JOIN
→ ALL LEFT + MATCHING RIGHT

RIGHT JOIN
→ ALL RIGHT + MATCHING LEFT

FULL JOIN
→ ALL LEFT + ALL RIGHT

This is the easiest way to remember the difference.


Important Note About the Extra Order

The original orders table has a foreign key:

SQL
customer_id INT REFERENCES customers(customer_id)

So this would normally fail:

SQL
INSERT INTO orders
VALUES (11, '2026-01-30', 9999, 999);

because customer 999 does not exist.

You do not need to break the foreign-key constraint just to understand FULL JOIN. The unmatched customers already demonstrate the part where the left side has no match.

To demonstrate an unmatched right row, you would need a dataset where the relationship is not enforced, such as a separate practice table without that foreign key.


Finding Unmatched Rows

A FULL JOIN can help identify records that exist on only one side.

Conceptually:

TEXT
LEFT ONLY
   +
MATCHED
   +
RIGHT ONLY

This makes FULL JOIN useful for comparing two datasets and finding missing records.


Common Beginner Mistakes

✗ Mistake ✓ Correct Understanding
FULL JOIN returns matching rows only It returns all rows from both tables
NULL means the row was removed The row remains; NULL indicates no match on the other side
FULL JOIN is the same as INNER JOIN INNER JOIN excludes unmatched rows
FULL JOIN always needs unmatched rows to work It still returns all rows even when everything matches
RIGHT and LEFT tables mean physical database positions They refer to the tables' positions in the JOIN statement

Placement Quick Points

TEXT
FULL JOIN
→ ALL LEFT ROWS
→ ALL RIGHT ROWS
→ MATCH WHERE POSSIBLE
→ NO MATCH = NULL
  • FULL JOIN keeps every row from both tables.
  • Matching rows are combined.
  • Unmatched rows remain.
  • Missing values appear as NULL on the opposite side.
  • It is useful for comparing two datasets and finding unmatched records.

Interview Questions

What is a FULL JOIN?

A FULL JOIN returns all rows from both tables, matching rows where possible.

What happens when there is no match?

The row is still returned, and the columns from the other table contain NULL.

What is the difference between INNER JOIN and FULL JOIN?
TEXT
INNER → Matching rows only
FULL  → All rows from both tables
When is FULL JOIN useful?

It is useful when you need to see all records from both sides, including unmatched records.

Can FULL JOIN show NULL values?

Yes. Unmatched rows contain NULL for columns from the other table.


Practice & Hands-On Exercises

Using customers and orders:

  1. Write a FULL JOIN:
SQL
SELECT c.customer_name, o.order_id
FROM customers c
FULL JOIN orders o
    ON c.customer_id = o.customer_id;
  1. Display customer names and order IDs.
  2. Identify customers without orders.
  3. Explain where NULL appears in the result.
  4. Compare FULL JOIN with INNER JOIN and LEFT JOIN.

💡 Tip: Test your queries using the in-browser interactive runner above.


Key Takeaway

TEXT
FULL JOIN
    ↓
ALL LEFT ROWS
+
ALL RIGHT ROWS
    ↓
MATCH WHEN POSSIBLE
    ↓
NO MATCH → NULL

FULL JOIN keeps all rows from both tables, combining matches and preserving unmatched rows with NULL values.

End of FULL JOIN