RIGHT JOIN, FULL JOIN and UNION in SQL
A RIGHT JOIN keeps every row of the right table. A FULL OUTER JOIN keeps every row of both tables. UNION stacks two results on top of each other and removes duplicates, while UNION ALL keeps them.
Do you need RIGHT JOIN?
Rarely. A RIGHT JOIN B is the same as B LEFT JOIN A, and most teams write LEFT JOIN only, because it reads more easily. SQLite supports RIGHT and FULL JOIN only since version 3.39 (2022).
When is FULL OUTER JOIN useful?
For comparing two lists, for example bank records against invoices, where either side may have rows the other doesn't:
SELECT b.id, i.idFROM bank bFULL OUTER JOIN invoices i ON i.ref = b.refWHERE b.id IS NULL OR i.id IS NULL;
This shows only the rows without a partner.
UNION or UNION ALL?
| UNION | UNION ALL | |
|---|---|---|
| Duplicates | removed | kept |
| Speed | slower (has to check) | faster |
Use UNION ALL when you know the parts don't overlap or you want every row, for example orders from two years' tables.
What are the rules for UNION?
Both queries need the same number of columns in the same order, with compatible types. The column names come from the first query.
Practise RIGHT JOIN and UNION Practise LEFT JOIN
Updated November 2026.