What is the difference between UNION and UNION ALL?

Answer

UNION combines the result sets of two SELECT queries and removes duplicate rows, requiring an implicit DISTINCT sort operation — slower because it must check for duplicates. UNION ALL combines result sets and includes all rows including duplicates — significantly faster since no deduplication is needed. Both require the same number of columns with compatible data types. Use UNION ALL when you know there are no duplicates (or duplicates are acceptable) to maximize performance. Example: combining results from archived_orders and current_orders tables where there can be no overlap.