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.

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

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.