Bird
0
0

What is the main difference between UNION and UNION ALL in PostgreSQL?

easy📝 Conceptual Q11 of 15
PostgreSQL - Set Operations and Advanced Queries
What is the main difference between UNION and UNION ALL in PostgreSQL?
A<code>UNION</code> removes duplicate rows, while <code>UNION ALL</code> keeps all rows including duplicates.
B<code>UNION</code> requires matching column names, <code>UNION ALL</code> does not.
C<code>UNION ALL</code> removes duplicates, <code>UNION</code> keeps duplicates.
D<code>UNION</code> can combine different numbers of columns, <code>UNION ALL</code> cannot.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the behavior of UNION

    UNION combines results from two queries and removes duplicate rows to give unique results.
  2. Step 2: Understand the behavior of UNION ALL

    UNION ALL combines results but keeps all rows, including duplicates.
  3. Final Answer:

    UNION removes duplicates, UNION ALL keeps duplicates. -> Option A
  4. Quick Check:

    Duplicates removed = UNION, duplicates kept = UNION ALL [OK]
Quick Trick: UNION removes duplicates; UNION ALL keeps all rows [OK]
Common Mistakes:
  • Thinking UNION ALL removes duplicates
  • Believing UNION allows different column counts
  • Confusing column name requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes