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:

everyone working in Engineering
Result

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:

keep every row, duplicates included
Result
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.