Bird
0
0

Consider this SQL query:

medium📝 Debug Q14 of 15
SQL - Set Operations
Consider this SQL query:
SELECT name FROM employees UNION SELECT name, department FROM managers;
What is the issue with this query?
AThe number of columns in both SELECT statements differ
BUNION cannot be used with SELECT statements
CThe query will return duplicate rows
DThe query is missing a WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Check column counts in SELECTs

    The first SELECT returns 1 column (name), the second returns 2 columns (name, department).
  2. Step 2: Understand UNION column rules

    UNION requires all SELECT statements to have the same number of columns with compatible types.
  3. Final Answer:

    The number of columns in both SELECT statements differ -> Option A
  4. Quick Check:

    UNION needs same columns = C [OK]
Quick Trick: UNION needs same column count in all SELECTs [OK]
Common Mistakes:
MISTAKES
  • Ignoring column count mismatch
  • Thinking UNION filters duplicates only
  • Assuming WHERE clause is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes