Home / Learn Secure SQL / CASE Expressions
CASE Expressions
If/else logic inside a query.
In shortIf/else logic inside a query.
What's actually going on
What it is
CASE WHEN ... THEN ... ELSE ... END lets a query compute a value conditionally, like an if/else inside SELECT.
Why it matters
It avoids pulling raw data back just to branch on it in application code, which also reduces how much data crosses the boundary.
Mechanically speaking
List conditions in order with WHEN, a result with THEN, and a fallback with ELSE.
Shows up in
- Web application code review
- Backend development
- Database administration
Labelling ordersSQL: edit and run
Each row gets a label computed entirely inside the query.
Check yourself
1. CASE expressions let you...
If/else inside SQL.