Nov 8, 2018

Performance of SQL UNION

The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL instead.

Union is slow for large result sets with many columns, as the two subselects need to be ordered, and each tuple needs to be compared with its subsequent tuple. So it is better to use UNION ALL if DISTINCT is not necessary.