The IF() function compares three expressions, as shown in the following syntax:
mysql>
IF(<expression1>, <expression2>, <expression3)
mysql>
If <expression1> evaluates to true, then the function returns <expression2>;
otherwise, the function returns <expression3>.
mysql>
mysql> SELECT IF(10>20, 'expression correct', 'expression incorrect');
+---------------------------------------------------------+
| IF(10>20, 'expression correct', 'expression incorrect') |
+---------------------------------------------------------+
| expression incorrect |
+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
Related examples in the same category