Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - CASE Expressions
Identify the error in this SQL query:

SELECT name FROM Employees ORDER BY CASE WHEN department = 'Sales' THEN 1 WHEN department = 'HR' THEN 2 ELSE 3;
AORDER BY cannot use CASE statements.
BIncorrect use of ELSE in CASE.
CMissing END keyword to close CASE statement.
DMissing THEN keyword after conditions.
Step-by-Step Solution
Solution:
  1. Step 1: Check CASE syntax completeness

    The CASE statement must end with the keyword END to close it.
  2. Step 2: Identify missing END keyword

    The query lacks END after ELSE 3, causing syntax error.
  3. Final Answer:

    Missing END keyword to close CASE statement. -> Option C
  4. Quick Check:

    CASE must end with END [OK]
Quick Trick: Always close CASE with END keyword [OK]
Common Mistakes:
  • Omitting END keyword
  • Misplacing ELSE clause
  • Thinking CASE not allowed in ORDER BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes