FULL JOIN
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.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in