SQL · Pattern 7 — Set Operators
UNION
UNION combines the results of two or more SELECT statements into a single result set while removing duplicate rows.
Source data — Pattern 7: Set Operators
All queries run against the shared employees table (see schema.sql). This pattern introduces the former_employees table. Topic 44 also introduces a retired_employees table to demonstrate combining multiple set operators in a single query.



What it does
UNION combines the results of two or more SELECT statements into a single result set while removing duplicate rows. Each SELECT statement must return the same number of columns in the same order with compatible data types.
Problem
Display the names of all current and former employees without duplicates.
SELECT first_name, last_name
FROM employees
UNION
SELECT first_name, last_name
FROM former_employees;
Result
