Bird
0
0

Identify the error in this searched CASE expression:

medium📝 Debug Q14 of 15
SQL - CASE Expressions
Identify the error in this searched CASE expression:
SELECT Name, CASE WHEN Age > 18 THEN 'Adult' WHEN Age < 18 THEN 'Minor' END AS AgeGroup FROM People;
AIncorrect use of THEN keyword
BNo error, query is correct
CNo END keyword to close CASE
DMissing ELSE clause for other cases
Step-by-Step Solution
Solution:
  1. Step 1: Check CASE syntax completeness

    The CASE has WHEN conditions, THEN results, and ends with END keyword properly.
  2. Step 2: Consider ELSE clause necessity

    ELSE is optional; if no ELSE, NULL is returned for unmatched cases, which is valid.
  3. Final Answer:

    No error, query is correct -> Option B
  4. Quick Check:

    ELSE optional, END required, syntax correct [OK]
Quick Trick: ELSE is optional; END is mandatory [OK]
Common Mistakes:
  • Assuming ELSE is always required
  • Forgetting END keyword
  • Misplacing THEN keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes