Bird
0
0

Why does the following query cause an error?

medium📝 Debug Q7 of 15
SQL - Set Operations
Why does the following query cause an error?
SELECT id, name FROM table1 UNION ALL SELECT id FROM table2;
AUNION ALL cannot combine different tables
BUNION ALL requires ORDER BY in both queries
CMissing WHERE clause in second SELECT
DNumber of columns in both SELECTs differ
Step-by-Step Solution
Solution:
  1. Step 1: Check column counts in both SELECTs

    First SELECT has 2 columns, second has 1 column.
  2. Step 2: Understand UNION ALL requirements

    Both SELECTs must have the same number of columns.
  3. Final Answer:

    Number of columns in both SELECTs differ -> Option D
  4. Quick Check:

    Column count mismatch causes error [OK]
Quick Trick: UNION ALL requires same number of columns in SELECTs [OK]
Common Mistakes:
MISTAKES
  • Using different column counts
  • Assuming UNION ALL works with any SELECTs
  • Ignoring error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes