Last updated: August 26, 2026.
UNION combines compatible query results and removes duplicate rows. UNION ALL keeps duplicates and usually avoids the cost of de-duplication.
Combine current and archived records
SELECT customer_id, order_date, order_total
FROM current_orders
UNION ALL
SELECT customer_id, order_date, order_total
FROM archived_orders
ORDER BY order_date DESC, customer_id;Requirements
| Rule | Meaning |
|---|---|
| Same number of columns | Each SELECT must return the same column count |
| Compatible types | Corresponding columns must be type-compatible |
| Output names | The first SELECT normally supplies result-column names |
| Final ordering | Place ORDER BY after the last SELECT to sort the combined result |
Use UNION when duplicate elimination is a requirement; otherwise prefer UNION ALL. Add a source label when readers need to know which query produced each row.