Bird
0
0

Why does PostgreSQL remove duplicates by default in UNION but not in UNION ALL?

hard📝 Conceptual Q10 of 15
PostgreSQL - Set Operations and Advanced Queries
Why does PostgreSQL remove duplicates by default in UNION but not in UNION ALL?
ABecause UNION ALL only works with numeric data
BTo ensure result sets represent true sets without duplicates
CTo avoid syntax errors in UNION queries
DBecause UNION ALL is slower and less efficient
Step-by-Step Solution
Solution:
  1. Step 1: Understand set theory in SQL

    UNION represents a mathematical set which does not allow duplicates.
  2. Step 2: Explain difference with UNION ALL

    UNION ALL returns all rows including duplicates, useful when duplicates matter.
  3. Final Answer:

    To ensure result sets represent true sets without duplicates -> Option B
  4. Quick Check:

    UNION removes duplicates to model sets [OK]
Quick Trick: UNION models sets, so removes duplicates by default [OK]
Common Mistakes:
  • Thinking UNION ALL is slower by default
  • Believing UNION ALL causes syntax errors
  • Assuming UNION ALL only works with numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes