What is the difference between UNION and UNION ALL?

Answer

UNION combines results from two SELECT statements and removes duplicate rows (implicit DISTINCT). UNION ALL combines results and keeps all rows including duplicates. Both require the same number of columns and compatible data types. Example: SELECT name FROM current_employees UNION SELECT name FROM former_employees; — returns unique names. With UNION ALL: all names including people who were employees twice. Performance: UNION ALL is significantly faster because it doesn't need to sort and deduplicate. Always prefer UNION ALL unless you specifically need deduplication. INTERSECT returns rows in both; EXCEPT returns rows in the first but not the second.