Home »
MySQL
MySQL IS NULL Operator
MySQL | IS NULL Operator: Learn about the MySQL IS NULL Operator, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 14, 2022
IS NULL Operator
In terms of a database management system, a null value is something that doesn't exist. A field with a null value is a field with no value. It is different from "0" or any real value. Usually, the null value tells us that value exists but it is not known or undefined for that row. The IS NULL Operator checks whether the column has NULL values or not.
IS NULL Operator Syntax
SELECT Column1, Column2, ...
FROM table_name WHERE column_name IS NULL;
Let us see some examples;
IS NULL Operator Examples
Suppose we have a table named "student_details" and inside this table, you have the following columns,
CASE 1: Using IS NULL operator to get all the NULL values
As you can see in the above table we have some NULL values in "student_department" so to get all the NULL values we can use this operator in the following manner:
SELECT * FROM student_details
WHERE student_department IS NULL;
As a result, we'll get all the details where the student department is NULL.
CASE 2: Using IS NULL with OR operator
If we have to use IS NULL with other operators then we can write,
Now, suppose I want to know the names of all the students where the student department has null values or gender have null values, in such case, we can simply use OR operator between two IS NULL conditions.
SELECT * FROM student_details
WHERE student_department IS NULL OR gender IS NULL;