SQL - CASE Function
SQL - CASE FunctionThe CASE statement selects one sequence of statements to execute. However, to select the sequence, the CASE statement uses a selector rather than multiple Boolean expressions.
Syntax for MySQL
Parameters or Arguments: selector - an optional expression, whose value is used to select one of several alternatives. condition_1, ... condition_n - Evaluated in the order listed. Once a condition is found to be true, the CASE function will return the result and not evaluate the conditions any further. result_1, ... result_n - The value returned once a condition is found to be true.
CASE [ selector ] WHEN condition_1 THEN result_1 ... WHEN condition_n THEN result_n ELSE result END