Example 1
Assign a salary tier to every employee based on their pay
Alice (120000) matches the first condition (>= 100000) and is assigned senior. Dave (95000) and Bob (75000) both match the second condition (>= 60000) and become mid. Carol (45000) matches neither and falls through to the ELSE branch, receiving junior. All four rows are updated in one pass without needing four separate UPDATE statements.
CREATE TABLE employees (name VARCHAR(50), salary INT, tier VARCHAR(20));
INSERT INTO
employees
VALUES
('Alice', 120000, NULL),
('Bob', 75000, NULL),
('Carol', 45000, NULL),
('Dave', 95000, NULL);UPDATE employees
SET
tier = CASE
WHEN salary >= 100000 THEN 'senior'
WHEN salary >= 60000 THEN 'mid'
ELSE 'junior'
END;
SELECT
name,
salary,
tier
FROM
employees
ORDER BY
salary DESC;| name | salary | tier |
|---|---|---|
| Alice | 120000 | senior |
| Dave | 95000 | mid |
| Bob | 75000 | mid |
| Carol | 45000 | junior |
The CASE WHEN syntax inside SET is identical across all supported engines.