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 NULL function inside a Where clause to find the records with NULL values. The basic syntax behind this MySQL IS NULL is as follows:

SELECT Column_Names  
FROM Table_Name
WHERE Column_Value IS NULL

Simple MySQL IS NULL Example 1

In this example, we show you the simple examples of the MySQL IS NULL operator. Here, 1 is Not a Null value, 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

MySQL IS NULL Example 2

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

MySQL IS NULL Operator 2

In this example, we use this MySQL IS NULL 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 is Null, and their Phone number is also 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