MySQL + SQL · Lesson 70
FULL OUTER JOIN in MySQL Using UNION
FULL OUTER JOIN
A FULL OUTER JOIN returns all rows from both tables — matched where possible, NULL where not. MySQL has no FULL JOIN keyword, so we combine LEFT and RIGHT with UNION.
MySQL Workaround
SELECT s.name, c.class_name
FROM students s LEFT JOIN classes c ON s.class_id=c.class_id
UNION
SELECT s.name, c.class_name
FROM students s RIGHT JOIN classes c ON s.class_id=c.class_id;All students AND all classes appear, with NULLs where there is no match.
Summary
- FULL OUTER JOIN = all rows from both sides.
- MySQL: simulate it with LEFT JOIN UNION RIGHT JOIN.