Case
is a conditional SQL expression: It searches for the first when
clause that has the same value as the case
clause and returns the value of the corresponding then
clause—or that of else
if nothing matches.
SELECT CASE column_name WHEN 0 THEN 'zero'
WHEN 1 THEN 'one'
ELSE 'not zero or one'
END
FROM …
Tutorial: Case
— Conditional Expressions
A more generic case
syntax: case when <condition>
(searched case)
Product specific features: if
, decode
.
The simple case
expression is defined in ISO/IEC 9075:2016-2 as mandatory feature F261-01.
The essence of SQL tuning in 200 pages
Buy on Amazon
(paperback only)
Paperback and PDF also available at Markus’ store.
Markus offers SQL training and consulting for developers working at companies of any size.
Learn more »