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.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.