IS NULL Operator

SQL · Filtering Rows

Theory

NULL means a value is missing or unknown. It is not zero and not an empty string. Because NULL is unknown, any comparison with it, even NULL = NULL, gives UNKNOWN rather than TRUE, so WHERE manager_id = NULL never matches anything. To test for missing values you must use IS NULL, and IS NOT NULL keeps rows that have a value.

This matters across SQL. Aggregates like SUM and AVG skip NULLs, COUNT(col) counts only non-NULL values while COUNT(*) counts all rows, and arithmetic with NULL returns NULL (salary + NULL is NULL). Use COALESCE to replace NULLs with a default. For example, employees with no manager_id are usually the top of the org chart, and IS NULL finds them.

Why we use it

Real data has gaps: unknown phone numbers, unassigned managers, orders not yet shipped. IS NULL is the only reliable way to find or exclude those rows, since ordinary comparisons silently ignore them.

When to use it

Use IS NULL to find missing values and IS NOT NULL to exclude them. Use COALESCE when you want to substitute a default instead of filtering. Never write = NULL or <> NULL.

How it works

  1. Read a row
  2. Look at the tested column
  3. Is the value NULL? Yes: IS NULL is TRUE: keep the row. No: IS NULL is FALSE: discard it.
  4. Repeat for every row
  5. Return rows with missing values

Syntax

SELECT columns FROM table
WHERE column IS NULL;

Example

SELECT * FROM employees WHERE manager_id IS NULL;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic