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.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response