Bird
0
0

What will be the output of the following query?

medium📝 query result Q5 of 15
SQL - Set Operations
What will be the output of the following query?
SELECT name FROM table1 UNION ALL SELECT name FROM table2 ORDER BY name DESC;
Given:
table1: ('John', 'Alice')
table2: ('Alice', 'Bob')
AJohn, Alice, Bob
BJohn, Bob, Alice, Alice
CJohn, Bob, Alice
DJohn, Bob, Alice, Alice (sorted descending)
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNION ALL behavior

    UNION ALL keeps duplicates, so 'Alice' appears twice.

  2. Step 2: Apply ORDER BY name DESC

    Sorting descending by name gives: 'John', 'Bob', 'Alice', 'Alice'.

  3. Final Answer:

    John, Bob, Alice, Alice (sorted descending) -> Option D
  4. Quick Check:

    UNION ALL keeps duplicates, ORDER BY sorts descending [OK]
Quick Trick: UNION ALL keeps duplicates; ORDER BY sorts final list [OK]
Common Mistakes:
MISTAKES
  • Removing duplicates with UNION ALL
  • Sorting ascending instead of descending
  • Ignoring duplicate 'Alice'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes