UNION ALL
combining result sets and keeping duplicates.
Overview
UNION ALL appends query results and preserves every row, including duplicates. Because it does not deduplicate, it is usually more direct and suits partitions, monthly tables, or sources where repeated values are valid. Column counts and corresponding types must still be compatible. If duplicates appear, determine whether they are business facts or already present in an input query.
Basic syntax
SELECT name FROM customers UNION ALL SELECT name FROM suppliers;
Examples
UNION ALL example
Combine customer and supplier names while preserving duplicates so the result can be compared directly with UNION.
Sample table
customers| name |
|---|
| Alice |
| Bob |
| Cindy |
suppliers| name |
|---|
| Alpha |
| Beta |
| Alice |
Run result
| name |
|---|
| Alice |
| Bob |
| Cindy |
| Alpha |
| Beta |
| Alice |
Common issues
No. Corresponding positions need the same number of type-compatible result columns.
UNION removes duplicates; when duplicates are acceptable, UNION ALL is usually more direct.
To sort the combined result, place ORDER BY at the end of the complete set query.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.