Skip to content

SQL FULL OUTER JOIN Keyword

FULL OUTER JOIN keeps every row of both tables. Rows that match are paired up; a row from either side with no partner still appears, with NULL in the other table’s columns. It combines a left join and a right join in one.

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

FULL JOIN is a shorter name for the same thing.

FULL OUTER JOIN: every row of both tables, matched where they can be

The examples use the Suppliers and Invoices tables from the example database.

A full join is the natural way to reconcile two lists. Matching invoices against the approved supplier list shows both kinds of mismatch at once: approved suppliers who have not invoiced, and invoices from suppliers who are not approved.

SELECT Suppliers.Name AS ApprovedSupplier, Invoices.InvoiceID, Invoices.Supplier AS InvoicedBy
FROM Suppliers
FULL OUTER JOIN Invoices ON Invoices.Supplier = Suppliers.Name
ORDER BY Invoices.InvoiceID;
ApprovedSupplier InvoiceID InvoicedBy
Northgate Transport
Hartwell Lighting 1001 Hartwell Lighting
Kestrel Catering 1002 Kestrel Catering
1003 Ashby Camera Hire
Kestrel Catering 1004 Kestrel Catering
  • Northgate Transport is approved but has sent no invoice, so the invoice columns are empty.
  • Invoice 1003 comes from Ashby Camera Hire, which is not on the approved list, so the supplier column is empty.
  • Everything else matches.

An inner join would have hidden both gaps, and a left or right join would have shown only one of them.

The row with no invoice sorts first here because SQLite and SQL Server put NULLs first in an ascending sort; PostgreSQL and Oracle put them last.

MySQL and Microsoft Access have no FULL OUTER JOIN. You can build one from a left join and a right join, joined with UNION, which also removes the second copy of each matched row, since both halves return it:

SELECT Suppliers.Name, Invoices.InvoiceID
FROM Suppliers LEFT JOIN Invoices ON Invoices.Supplier = Suppliers.Name
UNION
SELECT Suppliers.Name, Invoices.InvoiceID
FROM Suppliers RIGHT JOIN Invoices ON Invoices.Supplier = Suppliers.Name;