CASE Expression
Predict Output Medium
Question
What does this SQL produce?
Code
-- ages: 15, 25, 65
SELECT CASE WHEN age < 18 THEN "minor"
WHEN age < 65 THEN "adult" ELSE "senior" END
FROM users;
Hint
CASE evaluates conditions in order and returns the first match.
Explanation
CASE WHEN evaluates conditions in order. Age 15 < 18 → "minor". Age 25 ≥ 18 and < 65 → "adult". Age 65 ≥ 65 → "senior" (ELSE). Result: minor, adult, senior.
Related Resources
Related Lessons
- SQL Basics
Learn SQL.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.