- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements