UNION
UNION stacks the results of two SELECT statements into one combined result — useful when the same kind of data lives in more than one table.
Combining two tables
This lesson uses two separate tables: employees and contractors. Both have a name and department, so their results can be combined directly:
Both SELECTs need to return the same number of columns, in a compatible order — SQL matches them up by position, not by name.
UNION vs UNION ALL
Plain UNION removes duplicate rows from the combined result, the same way DISTINCT does. If you want every row kept, even exact duplicates, use UNION ALL — it's also faster, since it skips the extra work of checking for duplicates:
Note: if you just need one table's rows filtered by a condition that could be expressed with
OR, you don't need UNION — it's specifically for combining results from separate queries or tables.