SQL UNION vs UNION ALL (vs INTERSECT and EXCEPT): Differences, Duplicates, NULLs, Performance and Common Errors (Tested Examples)
UNION combines two result sets and removes duplicate rows, while UNION ALL keeps every row and skips the extra work. Here is how both behave with duplicates and NULLs, how much faster UNION ALL was in my test, and how to fix the common UNION errors, tested in PostgreSQL 16 and SQLite.