Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. SQL Dictionary
  3. IS NULL / IS NOT NULL

IS NULL / IS NOT NULL

An operator that checks whether a column's value is NULL (a state where no value exists). Because NULL is a special value, it cannot be evaluated using standard comparison operators.

Syntax

-- Retrieves rows where the value is NULL.
SELECT column_name FROM table_name WHERE column_name IS NULL;

-- Retrieves rows where the value is not NULL.
SELECT column_name FROM table_name WHERE column_name IS NOT NULL;

Syntax List

SyntaxDescription
IS NULLRetrieves rows where the column value is NULL. NULL is a special state indicating that a value is unset or unknown.
IS NOT NULLRetrieves rows where the column value is not NULL.

Sample Code

-- Retrieves employees with no retirement date set (NULL) — i.e., current employees.
SELECT name, hire_date FROM employees WHERE retire_date IS NULL;

-- Retrieves employees who have a retirement date set — i.e., former employees.
SELECT name, hire_date, retire_date FROM employees WHERE retire_date IS NOT NULL;

-- Finds employees with no department assigned.
SELECT name FROM employees WHERE department IS NULL;

-- Note the behavior difference when aggregating columns that contain NULL.
-- COUNT(*) counts all rows including NULLs, while COUNT(column) excludes NULLs.
SELECT COUNT(*) AS total_count, COUNT(bonus) AS bonus_count FROM employees;

-- Example using IFNULL (MySQL) to substitute a default value when the column is NULL.
SELECT name, IFNULL(bonus, 0) AS bonus FROM employees;

Result

-- Result of: SELECT name, hire_date FROM employees WHERE retire_date IS NULL;
-- +----------+------------+
-- | name     | hire_date  |
-- +----------+------------+
-- | Tanaka   | 2018-04-01 |
-- | Suzuki   | 2020-07-15 |
-- | Yamada   | 2022-01-10 |
-- +----------+------------+

Database-Specific Syntax

The IS NULL and IS NOT NULL syntax works consistently across all major databases.

SELECT name, hire_date FROM employees WHERE retire_date IS NULL;

The function used to replace NULL with a fallback value differs by database. The standard SQL COALESCE function works across all databases.

-- Standard SQL (works in all databases)
SELECT name, COALESCE(bonus, 0) AS bonus FROM employees;

MySQL provides the proprietary IFNULL function, and Oracle provides NVL.

-- MySQL only
SELECT name, IFNULL(bonus, 0) AS bonus FROM employees;

-- Oracle only
SELECT name, NVL(bonus, 0) AS bonus FROM employees;

Overview

In SQL, NULL represents a special state meaning "no value exists" or "unknown." NULL is neither 0 nor an empty string, so evaluating it with standard comparison operators (=, <>, etc.) always returns FALSE.

Using WHERE column = NULL will not retrieve NULL rows. Always use IS NULL instead. Similarly, WHERE column != NULL does not work as expected — use IS NOT NULL.

Arithmetic operations involving NULL (for example, salary + bonus when bonus is NULL) also return NULL. To substitute NULL with a value before calculating, use IFNULL(column, fallback) in MySQL or COALESCE(column, fallback) in standard SQL.

If you find any errors or copyright issues, please .