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,

IS NULL Operator Example 1

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;
IS NULL Operator Example 2

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;
IS NULL Operator Example 3


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.