Bird
0
0

Given two tables:

medium📝 query result Q13 of 15
PostgreSQL - Set Operations and Advanced Queries
Given two tables:
Table A:
id | value
1 | 'apple'
2 | 'banana'

Table B:
id | value
2 | 'banana'
3 | 'cherry'

What is the result of this query?
SELECT value FROM A UNION SELECT value FROM B ORDER BY value;
Aapple, banana, banana, cherry
Bapple, banana, cherry, banana
Cbanana, cherry
Dapple, banana, cherry
Step-by-Step Solution
Solution:
  1. Step 1: Combine values from both tables using UNION

    UNION removes duplicates, so 'banana' appears only once.
  2. Step 2: Order the combined results alphabetically

    Ordering by value gives: 'apple', 'banana', 'cherry'.
  3. Final Answer:

    apple, banana, cherry -> Option D
  4. Quick Check:

    UNION removes duplicates, so only one 'banana' [OK]
Quick Trick: UNION removes duplicates; check ordering carefully [OK]
Common Mistakes:
  • Including duplicate 'banana' with UNION
  • Ignoring ORDER BY effect
  • Confusing UNION with UNION ALL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes