
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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.
- Related Articles
- How can we distinguish between MySQL CROSS JOIN and INNER JOIN?
- Can we use IFNULL along with MySQL ORDER BY?
- How can we combine functions in MySQL?
- What are MySQL stored functions and how can we create them?
- How we distinguish between a planet and a star ?
- How can we calculate the Date in MySQL using functions?
- How can we transfer information between MySQL and data files?
- Can we distinguish numbers as lucky and unlucky numbers?
- How can we stuff a string with another one using MySQL functions?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How can I use IFNULL() function at the place of COALESCE() function in MySQL?
- How we can distinguish between the sound of an instrument, even if their frequency and loudness are the same?
- How can we distinguish one sound from another having the same pitch and loudness?
- How can we use group functions with non-group fields in MySQL SELECT query?
- How can we see the list of stored procedures and stored functions in a particular MySQL database?

Advertisements