0PricingLogin
SQL Academy · Lesson

UNION ALL vs UNION (Deduplication Cost)

Understand the dedup work UNION does and why UNION ALL is faster when you know there are no duplicates.

The Difference

  • UNION — combines and removes duplicates
  • UNION ALL — combines and keeps every row

UNION ALL Is Faster

Dedup is expensive (sort or hash). UNION ALL skips it entirely. When you know there can't be duplicates, always pick UNION ALL.

All lessons in this course

  1. UNION, INTERSECT, EXCEPT
  2. UNION ALL vs UNION (Deduplication Cost)
  3. CASE Expressions and Pivot Queries
  4. Crosstab Patterns (PostgreSQL crosstab())
← Back to SQL Academy