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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp