Both UNION and UNION ALL are used to combine the result sets of two or more SELECT statements.
So what’s the difference?
-
UNION: Removes duplicate rows from the combined result set.
-
UNION ALL: Includes all rows, including duplicates.
UNION ALL is significantly faster because it doesn’t have to check for duplicates.
If you know your combined results won’t have duplicates (or if you don’t care), always default to UNION ALL.
In a large-scale report that combines data from multiple tables (e.g., sales from 2024 and sales from 2025), using UNION ALL can dramatically reduce query time, getting data to stakeholders faster.
