MySQL IS NULL

The MySQL IS NULL is used to test whether the user given expression or column value is NULL or not. You can use this IS function inside a Where clause to find the records with NULL values. The basic syntax behind this is as follows:

SELECT Column_Names  
FROM Table_Name
WHERE Column_Value IS NULL

Simple MySQL IS NULL Example

In this example, we show you the simple examples of this one. Here, 1 is Not, 0 or NULL are Null Values. In the last statement, 1/0 is a NULL.

SELECT 1 IS NULL;

SELECT 0 IS NULL, NULL IS NULL;

SELECT 1/0 IS NULL, 0/1 IS NULL;
MySQL IS NULL Operator 1

For this demonstration, We are going to use the Employee Details table. The following screenshot shows you the data inside this table

Customer Table records 2

In this example, we use this one to return all the Employees details whose Middle Name is a NULL value.

SELECT 
       CustomerKey,
       FirstName, 
       MiddleName,
       LastName,
       YearlyIncome,
       Phone,
       Office,
       Mobile
 FROM EmployeeDetails
 WHERE MiddleName IS NULL;
MySQL IS NULL Operator 3

The following MySQL Query returns all the employee records whose Phone number is NULL.

SELECT 
       CustomerKey,
       FirstName, 
       MiddleName,
       LastName,
       YearlyIncome,
       Phone,
       Office,
       Mobile
 FROM EmployeeDetails
 WHERE Phone IS NULL;
MySQL IS NULL Operator 4

Until now, we are using this MySQL IS NULL on a single column. In this example, we use this operator to return all the employee details, whose Personal Phone number or Office numbers are NULL values

SELECT 
       CustomerKey,
       FirstName, 
       MiddleName,
       LastName,
       YearlyIncome,
       Phone,
       Office,
       Mobile
 FROM EmployeeDetails
 WHERE Phone IS NULL OR Office IS NULL;
MySQL IS NULL Operator 5

Here, we are finding the employees whose Middle, and their Phone number is Null.

SELECT 
       CustomerKey,
       FirstName, 
       MiddleName,
       LastName,
       YearlyIncome,
       Phone,
       Office,
       Mobile
 FROM EmployeeDetails
 WHERE MiddleName IS NULL AND Phone IS NULL;
MySQL IS NULL Operator 6