UNION vs UNION ALL

Published July 26, 2025 By Sai Sree Ram Gundepudi

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.

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article