Recall & Review
beginner
What does the CASE statement do in a SELECT query?
It allows you to create new columns with values that depend on conditions, like an IF-THEN-ELSE in your query.
Click to reveal answer
beginner
Write a simple CASE expression to show 'Adult' if age >= 18, else 'Minor'.
CASE WHEN age >= 18 THEN 'Adult' ELSE 'Minor' END
Click to reveal answer
intermediate
Can CASE be used to create multiple computed columns in one SELECT?
Yes, you can use multiple CASE expressions in the same SELECT to create several computed columns.
Click to reveal answer
intermediate
What happens if no WHEN condition matches and there is no ELSE in CASE?
The CASE expression returns NULL for that row.
Click to reveal answer
beginner
Why use CASE in SELECT instead of filtering rows with WHERE?
CASE lets you keep all rows but change or add column values based on conditions, while WHERE filters out rows.
Click to reveal answer
What keyword starts a conditional expression inside SELECT to create computed columns?
✗ Incorrect
The CASE keyword starts the conditional expression in SQL SELECT statements.
What does ELSE do in a CASE expression?
✗ Incorrect
ELSE provides a default value when none of the WHEN conditions are true.
If you want to label ages >= 65 as 'Senior', which WHEN clause is correct?
✗ Incorrect
The condition 'age >= 65' correctly selects seniors.
What will this CASE return if age = 20? CASE WHEN age < 18 THEN 'Child' ELSE 'Adult' END
✗ Incorrect
Since 20 is not less than 18, ELSE 'Adult' applies.
Can CASE expressions be nested inside each other in SELECT?
✗ Incorrect
CASE expressions can be nested to handle complex conditions.
Explain how to use CASE in a SELECT statement to create a new column based on conditions.
Think of CASE as an IF-THEN-ELSE inside your query.
You got /5 concepts.
Describe what happens if no WHEN condition matches and there is no ELSE clause in a CASE expression.
What does SQL do when no condition fits and no default is given?
You got /3 concepts.