Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - CASE Expressions
What will be the output of this query?
SELECT ProductID, CASE CategoryID WHEN 10 THEN 'Electronics' WHEN 20 THEN 'Clothing' END AS CategoryName FROM Products;

If CategoryID is 30 for some rows.
ACategoryName will be 'Clothing' for CategoryID 30
BCategoryName will be 'Electronics' for CategoryID 30
CCategoryName will be NULL for CategoryID 30
DQuery will fail with syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze CASE without ELSE

    Without ELSE, unmatched values return NULL.
  2. Step 2: Check CategoryID 30

    30 does not match 10 or 20, so result is NULL.
  3. Final Answer:

    CategoryName will be NULL for CategoryID 30 -> Option C
  4. Quick Check:

    CASE without ELSE returns NULL if no match [OK]
Quick Trick: No ELSE means unmatched CASE returns NULL [OK]
Common Mistakes:
  • Expecting ELSE default value
  • Assuming syntax error without ELSE
  • Thinking unmatched returns original value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes