IFNULL(expr1,expr2) : IFNULL « Control Flow Functions « MySQL Tutorial






If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2.

mysql>
mysql> SELECT IFNULL(1,0);
+-------------+
| IFNULL(1,0) |
+-------------+
|           1 |
+-------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT IFNULL(NULL,10);
+-----------------+
| IFNULL(NULL,10) |
+-----------------+
|              10 |
+-----------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT IFNULL(1/0,10);
+----------------+
| IFNULL(1/0,10) |
+----------------+
|        10.0000 |
+----------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT IFNULL(1/0,'yes');
+-------------------+
| IFNULL(1/0,'yes') |
+-------------------+
| yes               |
+-------------------+
1 row in set (0.00 sec)

mysql>








18.4.IFNULL
18.4.1.IFNULL(expr1,expr2)
18.4.2.Using IFNULL in where clause
18.4.3.Using IFNULL with data in a table
18.4.4.Create a table based on the result of IFNULL
18.4.5.IFNULL() with NULL and NOT NULL value
18.4.6.Use the IFNULL() function to specify a zero in place of the NULL figure