The SQL IFNULL function is used to replace NULL value with another value in MySQL. It’s similar to MS SQL Server’s ISNULL Function and Oracle’s NVL Function.

SQL IFNULL Function Syntax

IFNULL(expression1, expression2)

If expression1 is null, then IFNULL function will return expression2, otherwise it will return expression1.

SQL IFNULL Function Example

Table: Employees

EmployeeId FirstName LastName Department
203 Dehoo Ulooo Finance
205 Yuooi Yoiioa NULL
206 Bilaa Ioooo Finance

SELECT EmployeeId, IFNULL(Department, 'N/A') AS Department
FROM Employees;

The result will look like:

EmployeeId Department
203 Finance
205 N/A
206 Finance

Leave a Comment