The IFNULL() function returns a value based on whether a specified expression evaluates to NULL. : IFNULL « Function « SQL / MySQL






The IFNULL() function returns a value based on whether a specified expression evaluates to NULL.

     
mysql>
IFNULL(<expression1>, <expression2>)
mysql>
The function returns <expression1> if it is not NULL;
otherwise, it returns <expression2>.
mysql>
mysql> SELECT IFNULL(10*NULL, 'expression incorrect');
+-----------------------------------------+
| IFNULL(10*NULL, 'expression incorrect') |
+-----------------------------------------+
| expression incorrect                    |
+-----------------------------------------+
1 row in set (0.00 sec)

mysql>

   
    
    
    
    
  








Related examples in the same category

1.IFNULL() tests its first argument and returns it if it's not NULL, or returns its second argument otherwise
2.IF( ) and IFNULL( ) are useful for catching divide-by-zero operations
3.Use IFNULL( ) to map their results appropriately:
4.IFNULL() takes two arguments. If the first argument is not NULL, that argument is returned; otherwise, the fun
5.SELECT ISNULL(NULL), ISNULL(0), ISNULL(1);
6.The following expression returns expr2 if expr1 is NULL, and expr1 otherwise: