Conditionals and Branching
LockedLesson 4 of 25 · Syntax · Easy
Finish these first:Operators and Comparisons →Or pass the tests below to unlock it now.
The big idea
In SQL, you make an if / else decision using CASE WHEN ... THEN ...
Think of it like this: Think of SQL's `CASE WHEN ... THEN ... ELSE ... END` like reading an `if / else` sentence out loud in plain English.
Read the lesson
In SQL, you make an if / else decision using CASE WHEN ... THEN ... ELSE ... END:
SELECT CASE
WHEN 92 >= 90 THEN 'A'
ELSE 'B'
END;
SQL checks the WHEN rule first. If it is true, it gives back the THEN value; otherwise it gives back the ELSE value. Always close CASE with END.
Quick check
Which keyword finishes a SQL `CASE` expression?
Your challenge
Write a SQL CASE check that returns 'adult' when 20 >= 18 and 'minor' otherwise (type SELECT CASE WHEN 20 >= 18 THEN 'adult' ELSE 'minor' END;).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.conditionals (92% overlap). Branching control flow: if/else and switch/match expressions.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Conditionals and Branching.
Learn this first
- Operators and ComparisonsNot yet