FULL OUTER JOIN in SQL

11/22/2025

SQL FULL OUTER JOIN tutorial with examples and diagrams

Go Back

FULL OUTER JOIN in SQL – SQL Tutorial for Beginners

A FULL OUTER JOIN returns all rows from both tables, matching records where possible and filling unmatched fields with NULL. It is the most complete type of join because it combines the results of LEFT JOIN and RIGHT JOIN.

This beginnerโ€‘friendly SQL tutorial covers:

  • What FULL OUTER JOIN is

  • How it works

  • Syntax

  • Examples

  • FULL OUTER JOIN vs LEFT & RIGHT JOIN

  • Realโ€‘world use cases

  • Alternatives in MySQL (since MySQL does NOT support FULL OUTER JOIN)


SQL FULL OUTER JOIN tutorial with examples and diagrams

๐Ÿ”น What Is FULL OUTER JOIN?

A FULL OUTER JOIN returns:

  • All matching rows

  • All non-matching rows from the left table

  • All non-matching rows from the right table

If values don’t match, SQL uses NULL for missing data.

โœ” FULL OUTER JOIN = LEFT JOIN + RIGHT JOIN


๐Ÿ”ธ FULL OUTER JOIN Syntax (Standard SQL)

SELECT columns
FROM table1
FULL OUTER JOIN table2
ON table1.column = table2.column;

โš  Note: MySQL does not support FULL OUTER JOIN directly. Workarounds are shown later.


๐Ÿ”ธ Example Tables

๐Ÿง‘ users table

idname
1Amit
2Neha
4Sara

๐Ÿ“ฆ orders table

iduser_idproduct
11Mobile
23Laptop
34Tablet

Notice:

  • User 3 doesn’t exist in users table

  • User 2 has no orders


๐Ÿ”ธ FULL OUTER JOIN Example

SELECT users.name, orders.product
FROM users
FULL OUTER JOIN orders
ON users.id = orders.user_id;

โœ” Expected Output

nameproduct
AmitMobile
NehaNULL
SaraTablet
NULLLaptop

Explanation:

  • Amit matched โœ“

  • Neha has no orders → product = NULL

  • Sara matched โœ“

  • Laptop order has no matching user → name = NULL


๐Ÿ”น FULL OUTER JOIN vs LEFT JOIN vs RIGHT JOIN

FeatureLEFT JOINRIGHT JOINFULL OUTER JOIN
Return unmatched left rowsโœ”โŒโœ”
Return unmatched right rowsโŒโœ”โœ”
Return only matchesโŒโŒโŒ
Most complete joinโŒโŒโœ”

๐Ÿ”น FULL OUTER JOIN in MySQL (Not Supported Directly)

MySQL does not support FULL OUTER JOIN directly.
But you can simulate it using UNION of LEFT JOIN and RIGHT JOIN.

โœ” FULL OUTER JOIN Alternative in MySQL

SELECT u.name, o.product
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id

UNION

SELECT u.name, o.product
FROM users u
RIGHT JOIN orders o
ON u.id = o.user_id;

This returns the same result as FULL OUTER JOIN.


๐Ÿ”น FULL OUTER JOIN with WHERE Conditions

Example: Getting all records, only where product contains 'lap'

SELECT *
FROM users u
FULL OUTER JOIN orders o
ON u.id = o.user_id
WHERE o.product LIKE '%lap%';

๐Ÿ”น FULL OUTER JOIN With Multiple Tables

SELECT u.name, o.product, p.amount
FROM users u
FULL OUTER JOIN orders o
ON u.id = o.user_id
FULL OUTER JOIN payments p
ON o.id = p.order_id;

๐Ÿ”น Realโ€‘World Examples

โœ” Customer list including those without orders & orders without customers

SELECT c.name, o.order_id
FROM customers c
FULL OUTER JOIN orders o
ON c.id = o.customer_id;

โœ” All employees and their departments, including:

  • Employees without departments

  • Departments without employees

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

โœ” Students and course enrollments

SELECT s.name, c.course_name
FROM students s
FULL OUTER JOIN courses c
ON s.course_id = c.id;

๐Ÿ”น Best Practices

โœ” Use FULL OUTER JOIN only when needed (large performance cost)
โœ” In MySQL, use LEFT JOIN + RIGHT JOIN with UNION
โœ” Always index join columns
โœ” Use IS NULL to find unmatched rows
โœ” Keep tables clean to prevent orphan records


Summary

In this FULL OUTER JOIN tutorial, you learned:

  • What FULL OUTER JOIN does

  • How it returns both matching and non-matching rows

  • Syntax and examples

  • Differences from LEFT and RIGHT JOIN

  • MySQL alternative using UNION

FULL OUTER JOIN is powerful when you want a complete view of relationships between tables.