What Is A Full Join In Sql

7 min read

A full join in SQL is a type of join that combines rows from two or more tables based on a related column, returning all rows when there is a match in either table. It is also commonly called a FULL OUTER JOIN, and it is especially useful when you need to compare two datasets, find missing records, or merge information without losing rows from either side. Unlike an inner join, which only returns matching rows, a full join preserves unmatched rows from both tables and fills missing values with NULL. Understanding how a full join in SQL works can help you solve complex data problems, perform accurate reconciliation, and build more complete reports.

Easier said than done, but still worth knowing.

What Is a Full Join in SQL?

A full join in SQL is a relational operation that returns all records from the left table and all records from the right table. Think about it: if a row in the left table has a matching row in the right table, the result combines the columns from both rows. If there is no match, the result still includes the row, but the columns from the other table contain NULL values Most people skip this — try not to..

To understand this more clearly, imagine two tables: one containing customers and another containing orders. That's why it would also return every order, even if the customer record is missing or invalid. But a full join would return every customer, even if they have never placed an order. This makes a full join very different from an inner join, which only returns rows where a match exists in both tables.

The key idea is simple: a full join does not discard unmatched data from either side. It keeps everything and shows where the relationship is complete or incomplete Which is the point..

Full Join Syntax

The basic syntax for a full join in SQL is usually written like this:

SELECT 
    a.column1,
    b.column2
FROM table_a AS a
FULL OUTER JOIN table_b AS b
    ON a.id = b.id;

In many database systems, you can also write:

SELECT 
    a.column1,
    b.column2
FROM table_a AS a
FULL JOIN table_b AS b
    ON a.id = b.id;

The words FULL JOIN and FULL OUTER JOIN generally mean the same thing. The keyword OUTER is often optional, depending on the database system you are using That alone is useful..

The most important part of the query is the ON condition. This condition defines how the two tables are related. Think about it: for example, you might join a customers table and an orders table using customers. customer_id = orders.customer_id Worth knowing..

How a Full Join Works

A full join works by evaluating every row from both tables and checking whether the join condition is true. There are three possible outcomes for each row.

  1. The row matches in both tables.
    In this case, the result includes the combined data from both tables Easy to understand, harder to ignore..

  2. The row exists only in the left table.
    The result includes the left table row, while the right table columns are filled with NULL Simple as that..

  3. The row exists only in the right table.
    The result includes the right table row, while the left table columns are filled with NULL And that's really what it comes down to..

This behavior is what makes a full join so useful for identifying missing or extra records.

Here's one way to look at it: suppose you have a table of employees and a table of departments. A full join could show you:

  • Employees who belong to a department.
  • Employees who do not have a department assigned.
  • Departments that currently have no employees.

That kind of result is difficult to produce with a simple inner join because an inner join would hide both unmatched employees and empty departments.

Full Join vs Other Joins

To understand a full join in SQL more deeply, it helps to compare it with other common join types.

  • INNER JOIN returns only rows where there is a match in both tables.
  • LEFT JOIN returns all rows from the left table and matching rows from the right table.
  • RIGHT JOIN returns all rows from the right table and matching rows from the left table.
  • FULL JOIN returns all rows from both tables, matching where possible and using NULL where no match exists.

A simple way to remember the difference is this:

  • Use an inner join when you only care about complete matches.
  • Use a left join when you want to keep all rows from the first table.
  • Use a right join when you want to keep all rows from the second table.
  • Use a full join when you want to keep all rows from both tables.

This makes a full join especially valuable in data auditing, data migration, and comparison tasks And that's really what it comes down to..

Practical Example of a Full Join

Imagine you have two tables: employees and projects.

The employees

table has columns employee_id, name, and department. The projects table has columns project_id, project_name, and lead_employee_id, which references the employee_id in the employees table.

Here is the sample data:

employees

employee_id name department
1 Alice Engineering
2 Bob Marketing
3 Charlie Sales
4 Diana HR

projects

project_id project_name lead_employee_id
101 Website Redesign 1
102 Ad Campaign 2
103 Mobile App 5
104 Data Migration NULL

Notice that employee Charlie (ID 3) and Diana (ID 4) are not assigned to lead any projects. Conversely, Project 103 (Mobile App) references a lead_employee_id of 5, which does not exist in the employees table, and Project 104 (Data Migration) has a NULL lead.

The Query

To see the complete picture of all employees and all projects, regardless of whether they match, you would run:

SELECT 
    e.employee_id,
    e.name AS employee_name,
    p.project_id,
    p.project_name
FROM employees e
FULL JOIN projects p 
    ON e.employee_id = p.lead_employee_id;

The Result

employee_id employee_name project_id project_name
1 Alice 101 Website Redesign
2 Bob 102 Ad Campaign
3 Charlie NULL NULL
4 Diana NULL NULL
NULL NULL 103 Mobile App
NULL NULL 104 Data Migration

Interpreting the Output

  1. Alice and Bob (Rows 1–2): These are the matches. The ON condition evaluated to true, so columns from both tables are populated.
  2. Charlie and Diana (Rows 3–4): These represent left-table only rows (Outcome #2 from earlier). They exist in employees but have no corresponding entry in projects. The project columns are NULL.
  3. Mobile App and Data Migration (Rows 5–6): These represent right-table only rows (Outcome #3). They exist in projects but have no valid matching employee (ID 5 is missing, and NULL never equals NULL in a join condition). The employee columns are NULL.

This single result set immediately highlights data quality issues: two employees are unutilized, one project has an invalid foreign key, and another project lacks a lead entirely.

Database Compatibility Note

While the SQL standard defines FULL JOIN (or FULL OUTER JOIN), not all database engines support it natively Worth knowing..

  • Supported: PostgreSQL, SQL Server, Oracle, SQLite (since v3.39.0), DB2, Snowflake, BigQuery.
  • Not Supported (Native Syntax): MySQL, MariaDB (older versions).

Workaround for MySQL / MariaDB

If you are using a system that lacks native support, you can emulate a full join by combining a LEFT JOIN and a RIGHT JOIN with a UNION (which removes duplicates) or UNION ALL (if you handle the intersection manually).

-- MySQL / MariaDB Emulation
SELECT e.employee_id, e.name, p.project_id, p.project_name
FROM employees e
LEFT JOIN projects p ON e.employee_id = p.lead_employee_id

UNION

SELECT e.name, p.employee_id, e.That said, project_name
FROM employees e
RIGHT JOIN projects p ON e. On top of that, project_id, p. employee_id = p.

This produces the exact same result set as the standard `FULL JOIN` syntax.

## Performance Considerations

Because a full join must scan and return rows from **both** tables entirely—regardless of indexes on the join columns—it is often more resource-intensive than an inner or left join.

1.  **Result Set Size:** The maximum row count is the sum of rows in both tables (Cartesian product in worst-case non-equi joins, but typically `N + M` for standard equi-joins with unique keys).
2.  **Index Usage:** While indexes on the join columns (`employee_id`, `
Out the Door

Recently Completed

Others Went Here Next

More from This Corner

Thank you for reading about What Is A Full Join In Sql. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home