UNION vs UNION ALL in SQL

UNION combines two query results and removes duplicate rows; UNION ALL combines them and keeps every row, which is significantly faster.

Published September 19, 2026

UNION combines the result sets of two or more SELECT queries into one, automatically removing duplicate rows. UNION ALL does the same but keeps every row, including duplicates.

Common causes

  • Removing duplicates requires the database to sort or hash the combined result set to compare rows, which is extra work that UNION ALL skips entirely

How to fix it

  • Use UNION ALL by default whenever you know the two result sets won't overlap, or duplicates are acceptable/expected — it's meaningfully faster
  • Use UNION only when you specifically need duplicate rows removed from the combined result
  • Both require the combined SELECT statements to have the same number of columns with compatible data types, in the same order

Example

SELECT email FROM customers
UNION ALL
SELECT email FROM newsletter_subscribers;

FAQ

Which one should I use by default?

UNION ALL, unless you specifically need deduplication — it avoids the extra sorting/hashing work UNION performs to find and remove duplicate rows.

More SQL articles