What is the difference between UNION and UNION ALL?
What is the difference between UNION and UNION ALL?
Solution
UNION combines the result sets of two SELECT statements and removes duplicate rows from the combined result. UNION ALL combines them and keeps every row, including duplicates.
Because UNION ALL skips the duplicate-removal step, it is usually faster.
Option 1: both operators stack rows from the two queries. Joins are what add columns side by side.
Option 3: this reverses the two operators.
Option 4: set difference is done with EXCEPT (or MINUS), and the cartesian product comes from CROSS JOIN. Neither is done by UNION or UNION ALL.
Both operators need the same number of columns, with compatible data types, in the two queries.
Related questions:
2026: 21 May Shift 1
2026: 11 May Shift 2
2025: 30 May Shift 2
2025: 15 May Shift 2