Tsallaka zuwa abun ciki
Justice Tech School

FULL JOIN

FULL JOIN (FULL OUTER JOIN) returns all rows from both tables and fills the gaps with NULL on whichever side has no match. MySQL does not support it directly: combine a LEFT JOIN and a RIGHT JOIN with UNION instead.

Two small lists

Example
SELECT a.x AS left_side, b.x AS right_side
FROM (SELECT 1 AS x UNION SELECT 2) AS a
FULL JOIN (SELECT 2 AS x UNION SELECT 3) AS b ON a.x = b.x
ORDER BY COALESCE(a.x, b.x);

Result

left_side | right_side
1         | NULL
2         | 2
NULL      | 3
  • Only 2 matches in both lists. 1 appears with NULL on the right and 3 with NULL on the left. Older SQLite versions (before 3.39) lack FULL JOIN.

Exercise

Name the join that keeps everything.

SELECT * FROM a  JOIN b ON a.id = b.id;

Quiz Test

Which join returns all rows from both tables?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.