Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #505

FULL OUTER JOIN in SQL

FULL OUTER JOIN returns every row from both tables — matched rows combined, and unmatched rows from either side filled with NULL on the missing side.

employees departments

🔵 Shaded = everything from both tables is kept, matched or not.

Reference Tables Used in This Section

Every join note below uses these same two tables, so you can see exactly how each join type treats the same data differently.

employees

idnamedepartment_id
1Aman1
2Riya2
3Karan1
4NehaNULL

departments

iddepartment_name
1Engineering
2Marketing
3Sales

Notice: Neha has no department (department_id is NULL), and Sales has no employees at all. These two "unmatched" rows are what make the differences between join types visible.

Syntax

SELECT columns
FROM table1
FULL OUTER JOIN table2 ON table1.column = table2.column;

Example

SELECT e.name, d.department_name
FROM employees e
FULL OUTER JOIN departments d ON e.department_id = d.id;

Expected Output:

namedepartment_name
AmanEngineering
KaranEngineering
RiyaMarketing
NULLSales
NehaNULL

All 5 logical rows appear: 3 matched, Sales unmatched on the employee side, Neha unmatched on the department side.

Dialect Note: MySQL Has No Native FULL OUTER JOIN

PostgreSQL and SQL Server support FULL OUTER JOIN directly. MySQL does not — you have to simulate it by combining a LEFT JOIN and a RIGHT JOIN with UNION:

SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id
UNION
SELECT e.name, d.department_name
FROM employees e
RIGHT JOIN departments d ON e.department_id = d.id;

UNION (not UNION ALL) also removes the duplicate matched rows that would otherwise appear from both halves. See UNION.

Practical Use Case

Reconciliation reports — comparing two datasets and surfacing everything that exists in either one, such as matching a payments table against an invoices table to find discrepancies on both sides.

Common Mistakes

  • Trying to run FULL OUTER JOIN directly on MySQL — it will error; use the LEFT JOIN + UNION + RIGHT JOIN workaround above
  • Using UNION ALL instead of UNION in the MySQL workaround — this duplicates every matched row

Interview Relevance

Q: "How would you write a FULL OUTER JOIN in MySQL?" is a genuinely common trick question specifically because MySQL doesn't support the keyword — knowing the LEFT+RIGHT+UNION workaround is a strong signal of hands-on MySQL experience.

Practice Question

Using the reference tables, write the MySQL-compatible FULL OUTER JOIN workaround and confirm it produces the same 5 rows shown above.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →