Mega Code Archive

 
Categories / MySQL Tutorial / Control Flow Functions
 

CASE with condition

CASE WHEN [condition] THEN result     [WHEN [condition] THEN result ...]     [ELSE result] END Return the result for the first condition that is true. If there was no matching result value, the result after ELSE is returned, or NULL if there is no ELSE part. mysql> mysql> SELECT CASE     ->        WHEN 1>0 THEN 'true'     ->        ELSE 'false'     -> END; +-------------------------------------------------------------+ | CASE        WHEN 1>0 THEN 'true'        ELSE 'false' END | +-------------------------------------------------------------+ | true                                                        | +-------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>