CASE with value : CASE : Control Flow Functions MySQL TUTORIALS


MySQL TUTORIALS » Control Flow Functions » CASE »

 

CASE with value


CASE value
     WHEN [compare_valueTHEN result
    [WHEN [compare_valueTHEN result ...]
    [ELSE result]
END

Return the result where value=compare_value.

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 1
    ->            WHEN THEN 'one'
    ->            WHEN THEN 'two'
    ->            ELSE 'more'
    -> END;
+------------------------------------------------------------------------------------------------+
| CASE 1
           WHEN THEN 'one'
           WHEN THEN 'two'
           ELSE 'more'
END |
+------------------------------------------------------------------------------------------------+
| one                                                                                            |
+------------------------------------------------------------------------------------------------+
row in set (0.00 sec)

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Control Flow Functions
» CASE