sqlcmd.net validated sql reference
beginner null-handling MySQL MariaDB SQL Server PostgreSQL SQLite

Check For NULL Values With IS NULL

Use `IS NULL` and `IS NOT NULL` to filter rows based on whether a column has a value.

Docker-validated Not currently validation-green

Find employees who have no manager

Alice has no manager (NULL), so she is the top-level employee. WHERE manager_id = NULL would return no rows because comparisons with NULL are never true — IS NULL is the correct operator. Use IS NOT NULL to find the opposite: all employees who do have a manager.

Rows loaded before the example query runs.
Setup
CREATE TABLE employees (id INT, name VARCHAR(50), manager_id INT);

INSERT INTO
  employees (id, name, manager_id)
VALUES
  (1, 'Alice', NULL),
  (2, 'Bob', 1),
  (3, 'Carol', 1);
Shared across supported engines.
SQL
SELECT
  name
FROM
  employees
WHERE
  manager_id IS NULL
ORDER BY
  name;
Returned rows for the shared example.
name
Alice

Output is identical across all engines.

Where this command helps.

  • finding rows with missing or unset values
  • identifying top-level records with no parent reference

What the command is doing.

NULL represents a missing or unknown value. It cannot be compared with = or != — those comparisons always evaluate to unknown. The correct operators are IS NULL to find missing values and IS NOT NULL to find rows that have a value. This distinction matters in WHERE clauses, JOIN conditions, and CASE expressions.