The IF() function compares three expressions, as shown in the following syntax: : IF « Function « SQL / MySQL






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

1.Use an IF function to evaluate which designs sell over 500 units during the winter sales quarter
2.SELECT IF('02-29' < '03-01','02-29','03-01') AS earliest;
3.IF(condition, result1, result2)
4.Mapping NULL Values to Other Values for Display
5.display GB value with IF() that maps 0 to a dash