Reference

UNION / UNION ALL

Stack two result sets vertically. Both sides must have the same number of columns and compatible types. UNION deduplicates rows (a hash/sort pass over the combined result). UNION ALL keeps duplicates; default to this unless you specifically need the dedup.

Syntax #

sql
SELECT col_a, col_b FROM table_1
UNION ALL
SELECT col_a, col_b FROM table_2;

Example #

Loading SQL editor...
Tip

Default to UNION ALL, not UNION. The dedup in UNION requires sorting or hashing the combined output, which is expensive and usually unnecessary. If the two sides can't produce duplicates (different sources, disjoint filters) the dedup is pure overhead. Only use bare UNION when you explicitly need distinct rows across the combined set.