In general, outer joins allow us to specify how to deal with values that are present only in one of the tables being joined.

SELECT * FROM TableA
FULL OUTER JOIN TableB
ON TableA.col_match = TableB.col_match

A FULL OUTER JOIN returns all records from both tables, matching them where possible. If there is no match, NULL values will be returned for columns from the missing side. This join is useful when you need a complete view of both tables, including unmatched rows from each.

Note

We can use FULL OUTER JOIN along with WHERE clauses to get rows unique to either table - that is, rows not found in both tables (which functions as the opposite of an inner join):

SELECT * FROM TableA

FULL OUTER JOIN TableB ON TableA.col_match = TableB.col_match WHERE TableA.id IS null OR TableB.id IS null

Example

Given two tables:

Customers

idnamecity
1AliceNew York
2BobChicago
3CharlieSan Diego
4DavidMiami

Orders

idcustomer_idproduct
11Laptop
21Keyboard
33Monitor
45Mouse

Executing a FULL OUTER JOIN:

SELECT Customers.name, Orders.product  
FROM Customers  
FULL OUTER JOIN Orders ON Customers.id = Orders.customer_id;

Result:

nameproduct
AliceLaptop
AliceKeyboard
CharlieMonitor
BobNULL
DavidNULL
NULLMouse

Explanation:

  • Alice and Charlie had matching orders, so they appear with their respective products.
  • Bob and David had no orders, so their product column is NULL.
  • The order for customer ID 5 has no matching customer, so NULL appears in the name column.

Key Differences from Other Joins

Join TypeIncludes Unmatched Rows?Where Do NULLs Appear?
INNER JOIN❌ NoNo unmatched rows
LEFT JOIN✅ Yes (left table)Right table columns
RIGHT JOIN✅ Yes (right table)Left table columns
FULL OUTER JOIN✅ Yes (both tables)Both sides where no match exists