0
0
SQLquery~5 mins

Searched CASE syntax in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the Searched CASE syntax in SQL?
It allows you to perform conditional logic in SQL queries by evaluating multiple conditions and returning a result for the first true condition.
Click to reveal answer
beginner
Write the basic structure of a Searched CASE expression.
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... ELSE default_result END
Click to reveal answer
intermediate
How does the Searched CASE differ from the Simple CASE syntax?
Searched CASE evaluates boolean conditions in each WHEN clause, while Simple CASE compares an expression to fixed values.
Click to reveal answer
beginner
Can the ELSE clause in a Searched CASE be omitted? What happens then?
Yes, it can be omitted. If no WHEN condition matches, the CASE expression returns NULL.
Click to reveal answer
beginner
Give a real-life example where Searched CASE is useful.
For example, assigning grades based on score ranges: CASE WHEN score >= 90 THEN 'A' WHEN score >= 80 THEN 'B' ELSE 'F' END
Click to reveal answer
What does the Searched CASE syntax evaluate in each WHEN clause?
ATable names
BFixed values
CColumn names
DBoolean conditions
What will the CASE expression return if no WHEN condition matches and ELSE is omitted?
ANULL
B0
CError
DEmpty string
Which keyword starts a searched CASE expression?
AWHEN
BCASE
CIF
DSELECT
In Searched CASE, what does the ELSE clause do?
AProvides a default result if no WHEN condition is true
BEnds the CASE expression
CSpecifies the first condition
DIs mandatory
Which of these is a valid Searched CASE syntax?
ACASE age = 18 THEN 'Adult' END
BCASE age WHEN 18 THEN 'Adult' END
CCASE WHEN age < 18 THEN 'Minor' ELSE 'Adult' END
DCASE age < 18 THEN 'Minor' END
Explain how the Searched CASE syntax works in SQL and when you would use it.
Think about how you decide between multiple choices based on conditions.
You got /4 concepts.
    Write a Searched CASE expression that categorizes a numeric score into 'High', 'Medium', or 'Low'.
    Use score ranges like >80, >50, else.
    You got /4 concepts.