SQLBeginner#sets

UNION vs UNION ALL?

Both stack two result sets with matching column counts and types. UNION removes duplicate rows (needs a sort/hash, slower); UNION ALL returns everything as-is and is faster.

Example
SELECT city FROM customers
UNION      -- distinct cities
SELECT city FROM suppliers;

SELECT city FROM customers
UNION ALL  -- keeps duplicates
SELECT city FROM suppliers;

Related Questions

1
SQLIntermediate#sets

What are INTERSECT and EXCEPT/MINUS?

Open
2
SQLIntermediate#indexes#performance

What is an index? What are the trade-offs?

Open
3
SQLAdvanced#indexes

Clustered vs non-clustered index?

Open