What is the use of MySQL IFNULL() control flow function?


MySQL IFNULL() control flow function will return the first argument if it is not NULL otherwise it returns the second argument.

Syntax

IFNULL(expression1, expression2)

Here if expression1 is not NULL then IFNULL() will return expression1 otherwise expression2. It will return NULL if both of the arguments are NULL. Following example will exhibit this −

mysql> Select IFNULL(NULL,'Ram');
+--------------------+
| IFNULL(NULL,'Ram') |
+--------------------+
| Ram                |
+--------------------+
1 row in set (0.00 sec)

mysql> Select IFNULL('Shyam','Ram');
+-----------------------+
| IFNULL('Shyam','Ram') |
+-----------------------+
| Shyam                 |
+-----------------------+
1 row in set (0.00 sec)

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

Updated on: 22-Jun-2020

100 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements