How can we distinguish between MySQL IFNULL() and NULLIF() functions?



Actually, both MySQL IFNULL() and NULLIF() functions are having an almost same syntax as given below −

The syntax of IFNULL()

IFNULL(expression1, expression2)

The syntax of NULLIF()

NULLIF(expression1, expression2)

They can be distinguished in the way they return the first argument as result. IFNULL() function will return the first argument as a result if it is not NULL and NULLIF() function will return the first argument as a result if both the arguments are not same.

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

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

From the above result set of both the functions, it looks like they are similar but IFNULL() function returns ‘Ram’ because of it the first argument of it and it is not NULL. On the other hand NULLIF() function returns ‘Ram’ because it is the first argument and it is different from the second argument.

Updated on: 2020-06-20T13:38:38+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy