SQLMentor // glossary

CASE Expression

The CASE expression evaluates a list of conditions and returns the value from the first one that's true — SQL's equivalent of if/elseif/else, usable anywhere a value is expected, including SELECT, WHERE, and ORDER BY.

Simple CASE compares one expression against several values; searched CASE evaluates independent boolean conditions in order and stops at the first match, falling through to ELSE (or NULL, if no ELSE and nothing matches).

It's commonly used to bucket continuous values into labels, pivot rows into columns, or apply conditional logic inline without a separate lookup table.

SELECT first_name,
       CASE
         WHEN salary >= 10000 THEN 'Senior'
         WHEN salary >= 6000  THEN 'Mid'
         ELSE 'Junior'
       END AS band
FROM employees;