Skip to content

SQL FULL JOIN Clause

Syntax

The FULL JOIN clause in SQL is used to combine rows from two tables. It returns all rows from both tables, with NULL for unmatched rows from either table.

-- Full join two tables on a common column
SELECT table1.column1, table2.column2
FROM table1
FULL JOIN table2
ON table1.common_column = table2.common_column;

Example

-- Retrieve all employees and all departments, including unmatched rows from both sides
SELECT employees.name, departments.department_name
FROM employees
FULL JOIN departments
ON employees.department_id = departments.id;
/* Output:
| name | department_name |
|------------|-----------------|
| John Doe | Sales |
| Jane Smith | Marketing |
| Alice Brown| HR |
| Bob White | NULL |
| NULL | IT |
*/