UNION vs UNION ALL

Both combine results from two queries:

UNION

Removes duplicate rows.

SELECT department_id FROM employees
UNION
SELECT department_id FROM departments;

UNION ALL

Includes all rows, even duplicates.

SELECT department_id FROM employees
UNION ALL
SELECT department_id FROM departments;

Use UNION ALL when performance is more important and duplicates are acceptable.