FULL JOIN

Basic SQL
≈ 1 min read

FULL JOIN preserves both sides

FULL JOIN, also called FULL OUTER JOIN, returns matching rows while also preserving unmatched rows from both the left and right sides.

SELECT u.id AS user_id, o.id AS order_id
FROM users AS u
FULL JOIN orders AS o ON o.user_id = u.id;

If a user and order match the condition, they appear in one result row. If no match exists, the missing side is represented by NULL values.

When FULL JOIN is useful

It is useful when you need to see not only matches but also differences between two sets: for example, which records exist only in the first source, only in the second, or in both.

FULL JOIN support depends on the database system. It is a standard SQL construction, but some popular database systems do not support it directly. In a real project, always account for the dialect of the database you use.