Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - Set Operations
Identify the error in this SQL query:
SELECT name FROM table1 UNION ALL ORDER BY name SELECT name FROM table2;
ASELECT statements must have different column names
BUNION ALL cannot be used with ORDER BY
CMissing semicolon after first SELECT
DORDER BY is placed incorrectly between UNION ALL and second SELECT
Step-by-Step Solution
Solution:
  1. Step 1: Check UNION ALL syntax

    UNION ALL combines two SELECT queries; ORDER BY must come after both queries, not between.
  2. Step 2: Identify ORDER BY placement error

    ORDER BY is incorrectly placed between UNION ALL and second SELECT, causing syntax error.
  3. Final Answer:

    ORDER BY is placed incorrectly between UNION ALL and second SELECT -> Option D
  4. Quick Check:

    ORDER BY after UNION ALL queries = D [OK]
Quick Trick: ORDER BY must follow all UNION ALL queries [OK]
Common Mistakes:
MISTAKES
  • Placing ORDER BY between UNION ALL and second SELECT
  • Thinking UNION ALL disallows ORDER BY
  • Assuming column names must differ

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes