0
0
SQLquery~5 mins

Simple CASE syntax in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the Simple CASE syntax in SQL?
The Simple CASE syntax helps you choose a value based on matching a single expression to different possible values, similar to a multiple-choice decision.
Click to reveal answer
beginner
Write the basic structure of a Simple CASE expression in SQL.
CASE expression WHEN value1 THEN result1 WHEN value2 THEN result2 ... ELSE default_result END
Click to reveal answer
intermediate
What happens if none of the WHEN conditions match and there is no ELSE clause in a Simple CASE expression?
The CASE expression returns NULL if no WHEN condition matches and there is no ELSE clause.
Click to reveal answer
intermediate
How is Simple CASE different from Searched CASE in SQL?
Simple CASE compares one expression to multiple values. Searched CASE evaluates multiple boolean conditions independently.
Click to reveal answer
beginner
Example: What will this SQL return? <br>
SELECT CASE grade WHEN 'A' THEN 'Excellent' WHEN 'B' THEN 'Good' ELSE 'Other' END AS performance FROM students;
It returns 'Excellent' if grade is 'A', 'Good' if grade is 'B', and 'Other' for any other grade.
Click to reveal answer
What keyword starts a Simple CASE expression in SQL?
ASELECT
BIF
CSWITCH
DCASE
In Simple CASE, what does the expression after CASE represent?
AThe value to compare against WHEN values
BThe result to return
CA boolean condition
DThe default value
What does the ELSE clause do in a Simple CASE expression?
AIs required for CASE to work
BSpecifies the default result if no WHEN matches
CStarts the CASE expression
DEnds the CASE expression
If no WHEN matches and no ELSE is provided, what is returned?
ANULL
B0
CError
DEmpty string
Which of these is a valid Simple CASE expression?
ACASE WHEN score > 90 THEN 'A' ELSE 'B' END
BIF score = 90 THEN 'A' ELSE 'B'
CCASE score WHEN 90 THEN 'A' WHEN 80 THEN 'B' ELSE 'C' END
DSWITCH(score) WHEN 90 THEN 'A' ELSE 'B'
Explain how the Simple CASE syntax works in SQL and give a real-life example.
Think about choosing an output based on one value matching several options.
You got /5 concepts.
    Describe the difference between Simple CASE and Searched CASE expressions in SQL.
    Focus on how conditions are checked in each type.
    You got /3 concepts.