Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain LEFT, RIGHT and FULL OUTER JOIN with a small example, and say why many teams avoid RIGHT JOIN. Does MySQL 8.4 support FULL OUTER JOIN?

A LEFT JOIN keeps every row of the left table, a RIGHT JOIN keeps every row of the right table, and a FULL OUTER JOIN keeps every row of both, filling the missing side with NULLs when there is no match. Teams avoid RIGHT JOIN because any RIGHT JOIN can be rewritten as a LEFT JOIN by swapping the tables, which reads more naturally. MySQL 8.4 does not support FULL OUTER JOIN; we emulate it with a LEFT JOIN UNION ALL the right-only rows.

Why this question is asked

Outer joins are how we ask questions that include absence: customers without orders, products never sold, records present in one system but not another. Interviewers ask for the three kinds together because the explanation shows whether we think of joins in terms of which rows are preserved, and because the MySQL limitation catches people who move between databases. In this answer, we will use two tiny tables to show each join, explain why RIGHT JOIN is rare in practice, write the MySQL emulation of FULL OUTER JOIN, and see where full joins are most useful.

1A Quick Recap: Preserved and Optional Sides

An inner join returns only pairs of rows that match. An outer join also returns rows that found no match on the other side, padding the missing columns with NULL. The difference between the three outer joins is just which side is preserved: which table's rows are guaranteed to appear at least once. In LEFT JOIN it is the table written first, in RIGHT JOIN the table written second, and in FULL JOIN both.

We will use two small tables. employees has Ana in department 10, Ben in department 20 and Cem with no department. departments has 10 Sales, 20 Support and 30 Legal, which has no employees.

2The Three Joins on the Same Data

SQL
SELECT e.name, d.name AS dept
FROM employees e LEFT JOIN departments d ON d.id = e.dept_id;
-- Ana | Sales
-- Ben | Support
-- Cem | NULL every employee, even without a department
SELECT e.name, d.name AS dept
FROM employees e RIGHT JOIN departments d ON d.id = e.dept_id;
-- Ana | Sales
-- Ben | Support
-- NULL | Legal every department, even without employees
SELECT e.name, d.name AS dept
FROM employees e FULL OUTER JOIN departments d ON d.id = e.dept_id;
-- Ana | Sales
-- Ben | Support
-- Cem | NULL
-- NULL | Legal every row of both tables
Which unmatched rows each join keeps
JoinMatched pairsCem (left only)Legal (right only)
INNERyesnono
LEFTyesyes, dept NULLno
RIGHTyesnoyes, name NULL
FULL OUTERyesyesyes

The matched rows, Ana and Ben, appear in all three results. What changes is which unmatched rows are added: Cem from the left table, Legal from the right table, or both.

3Why Many Teams Avoid RIGHT JOIN

Any RIGHT JOIN can be turned into a LEFT JOIN by swapping the order of the two tables. departments d LEFT JOIN employees e gives exactly the same rows as employees e RIGHT JOIN departments d. So RIGHT JOIN never adds expressive power.

The reason to prefer LEFT JOIN is readability. People read a query top to bottom and think of the first table in FROM as the subject: we start from departments and attach what we can find. With LEFT JOINs only, every join in a chain follows that rule, and the preserved table is always the one we started with. Mixing LEFT and RIGHT joins in one query forces the reader to track which side is preserved at each step, which is where mistakes happen. Many style guides therefore say: start FROM the table whose rows you want to keep, and use LEFT JOIN.

4FULL OUTER JOIN in MySQL 8.4

PostgreSQL, Oracle and SQL Server support FULL OUTER JOIN. MySQL, including 8.4, does not; writing it is a syntax error. We emulate it by combining the left join, which gives matches and left-only rows, with the right-only rows.

SQL
SELECT e.name, d.name AS dept
FROM employees e LEFT JOIN departments d ON d.id = e.dept_id
UNION ALL
SELECT e.name, d.name
FROM employees e RIGHT JOIN departments d ON d.id = e.dept_id
WHERE e.id IS NULL;
-- Ana | Sales
-- Ben | Support
-- Cem | NULL
-- NULL | Legal

The second query keeps only departments with no matching employee, by testing the employee's primary key for NULL, so the matched rows are not repeated. That is why UNION ALL is correct here and better than UNION: UNION would also remove legitimate duplicate rows, such as two employees who happen to have the same name in the same department, and it costs a sort. The test must use a column that cannot be NULL in a real match, such as the primary key; testing a nullable column like e.name would wrongly include matched rows where that column is NULL. The second half can equally be written as departments LEFT JOIN employees WHERE e.id IS NULL, in keeping with the left-only style.

5Where Full Joins Are Useful

Full outer joins are most at home in reconciliation, comparing two sources that should contain the same things. Joining payments in our database to a provider's settlement file on the payment reference shows, in one result, payments the provider never settled, settlements we have no payment for, and matches whose amounts differ. Data migration checks, comparing old and new tables, and merging two lists, such as customers from two acquired companies, follow the same pattern. Outside such comparisons, a FULL JOIN in an application query is often a sign that the question could be stated more simply.

6Follow-up questions

Do outer joins perform worse than inner joins?

Not inherently, but they give the optimizer less freedom. An inner join can be reordered freely, while an outer join constrains the order, because the preserved side must be kept. In queries with many joins this can lead to slower plans.

What does COALESCE do in a full join result?

It picks the first non-NULL value, so COALESCE(a.ref, b.ref) gives a single key column for rows that came from either side. It is the usual way to present a reconciliation result with one identifier per row.

Is a LEFT JOIN with WHERE right_key IS NULL the same as NOT EXISTS?

It gives the same rows, the left rows without a match, and is called an anti-join. Modern planners usually execute both as an anti-join. NOT EXISTS states the intent more directly, while the LEFT JOIN form is needed when we also want columns from other joins in the same query.

7Conclusion

In this answer, we saw that LEFT, RIGHT and FULL OUTER JOIN differ only in which side's unmatched rows are kept, the left, the right or both, with NULLs for the missing side. RIGHT JOIN can always be rewritten as a LEFT JOIN by swapping tables, which reads more naturally, so many teams avoid it. MySQL 8.4 has no FULL OUTER JOIN, and we emulated it with a LEFT JOIN UNION ALL the right-only rows tested by primary key. Full joins shine in reconciliation between two sources.

What to say in the interviewAbout 90 seconds aloud

Open with

All three are outer joins, so they return the matching pairs like an inner join, plus the rows that found no match, with NULLs for the missing side.

Then, if they want more

The only difference is which side is preserved. With employees and departments: a LEFT JOIN from employees keeps every employee, so an employee with no department shows with a NULL department. A RIGHT JOIN keeps every department, so an empty department like Legal shows with a NULL employee.

A FULL OUTER JOIN keeps both, so I see the employee without a department and the department without employees in one result.

Teams avoid RIGHT JOIN because it never adds anything: I can swap the two tables and write a LEFT JOIN with the same result, and starting from the table whose rows I want to keep and then left joining reads naturally and avoids confusion in long chains.

MySQL 8.4 does not support FULL OUTER JOIN, while PostgreSQL, Oracle and SQL Server do. In MySQL I emulate it with the LEFT JOIN, then UNION ALL, then the right-side rows with no match, which I get with a RIGHT JOIN or a swapped LEFT JOIN where the left primary key is NULL.

I use UNION ALL, not UNION, because the halves do not overlap and UNION would remove legitimate duplicates. Full joins are most useful for reconciliation, such as comparing our payments with a provider's settlement file.

About this answer

Last updated
12 November 2026
Versions it names
MySQL 8.4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain LEFT, RIGHT and FULL OUTER JOIN with a small example, and say why many teams...": https://scrivio-interview-library.netlify.app/databases/sql-joins-and-subqueries/7610c71647/