Bird
0
0

Why is it important to include an ELSE clause when using CASE in a WHERE clause?

hard📝 Conceptual Q10 of 15
SQL - CASE Expressions
Why is it important to include an ELSE clause when using CASE in a WHERE clause?
ATo improve query performance by indexing
BTo handle all possible cases and avoid NULL results that cause unexpected filtering
CTo create new columns in the output
DTo allow CASE to be used in GROUP BY clauses
Step-by-Step Solution
Solution:
  1. Step 1: Understand CASE behavior without ELSE

    If ELSE is missing, CASE returns NULL for unmatched conditions.
  2. Step 2: Effect on WHERE filtering

    NULL in WHERE condition causes rows to be excluded unexpectedly.
  3. Final Answer:

    To handle all possible cases and avoid NULL results that cause unexpected filtering -> Option B
  4. Quick Check:

    ELSE prevents NULL filtering issues in CASE [OK]
Quick Trick: Always include ELSE to avoid NULL in CASE [OK]
Common Mistakes:
  • Omitting ELSE and getting NULL results
  • Thinking ELSE improves performance
  • Confusing CASE in WHERE with GROUP BY usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes