Home › SQL Tutorial › SQL CASE
SQL CASE
If-then-else inside a query.
CASE returns a value depending on conditions, like if / else if / else. Functions such as COALESCE(x, y) (or IFNULL / ISNULL) replace NULL with a default.
Example code
SELECT id,
CASE
WHEN amount >= 50 THEN 'big'
ELSE 'small'
END AS size
FROM Orders;