SQL Basics | DML: Data Manipulation Language | IS NULL, IS NOT NULL
These conditions check whether a field value is empty, that is, whether it is NULL.
IS NULL, IS NOT NULL syntax
The IS NULL condition is as follows.
SELECT "field_name"
FROM "table_name"
WHERE "field_name" IS NULL
To query the opposite of the IS NULL condition, use the following.
SELECT "field_name"
FROM "table_name"
WHERE "field_name" IS NOT NULL
IS NULL example
Given the store_information table below, suppose sales is empty.
store_information table
| store_name | sales | txn_date |
|---|---|---|
| Los Angeles | 1500 | Jan-05-2018 |
| San Diego | 250 | Jan-07-2018 |
| Los Angeles | 300 | Jan-08-2018 |
| Boston |
Enter the following command.
SELECT *
FROM store_information
WHERE sales IS NULL
The result is as follows.
| store_name | sales | txn_date |
|---|---|---|
| Boston |
IS NOT NULL example
When sales is not empty, use the following.
SELECT *
FROM store_information
WHERE sales IS NOT NULL
The result is as follows.
| store_name | sales | txn_date |
|---|---|---|
| Los Angeles | 1500 | Jan-05-2018 |
| San Diego | 250 | Jan-07-2018 |
| Los Angeles | 300 | Jan-08-2018 |