beginnerSet Operators — UNION, INTERSECT, EXCEPT/MINUS
What's the difference between UNION and UNION ALL, and which should you default to?
UNION combines both result sets and removes duplicate rows, requiring a sort or hash pass over the entire combined output. UNION ALL combines them with no deduplication at all, which is strictly cheaper. Default to UNION ALL unless you specifically know duplicates can occur and need to be removed.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
What's the difference between UNION and UNION ALL, and which should you default to?