Part 77: Combining Results with UNION & UNION ALL

Part 77 Technology Updated September 12, 2026

Part 77: Combining Results with UNION & UNION ALL

UNION and UNION ALL combine rows from two or more queries into a single result set.


1. UNION vs UNION ALL

  • UNION: Combines rows and removes duplicates (performs an expensive sort/unique operation).
  • UNION ALL: Combines rows and keeps all duplicates (fast memory append).

Performance Rule: Always use UNION ALL unless you explicitly require deduplication!

SELECT customer_email AS email FROM customers
UNION ALL
SELECT supplier_email AS email FROM suppliers;

Key Takeaways

  • Both queries must have matching column counts and compatible data types.
  • Always default to UNION ALL for maximum performance.

In Part 78, we explore Set Difference with EXCEPT / MINUS!