UNION vs UNION ALL in SQL: What’s the Difference?

UNION removes duplicate rows across combined results. UNION ALL keeps everything and is usually faster. When to use each.

customers first_name last_name city result first_name · city
SELECT chooses which columns appear in the result.

Stacking result sets

Both append rows from query A under query B. Column count and compatible types must match.

SELECT city FROM customers
UNION
SELECT city FROM customers WHERE country = 'USA';

UNION deduplicates. UNION ALL would keep repeats.

Performance intuition

UNION must detect duplicates (sort/hash). UNION ALL streams rows. If you already know sets are disjoint — or duplicates are fine — prefer UNION ALL.

One-line summary

UNION = combine and remove duplicates. UNION ALL = combine and keep every row (usually faster).

FAQ

Should I use UNION or UNION ALL?

Use UNION ALL unless you truly need to remove duplicates across the combined result — UNION ALL is cheaper.

Try it yourself

The fastest way to lock this in is a short drill on the same Northstar Market tables.

Practice DISTINCT first

Related guides