Learn SQL
SQL NULL Explained: How Missing Values Work and Why They Matter
NULL is SQL's way of saying a value is missing or unknown — and it behaves differently from almost every other value beginners expect.
On This Page
Missing is not the same as empty
Real datasets are rarely complete. A customer may not have provided a phone number. An employee may not have a department assigned yet. A measurement may have failed before the value was recorded. SQL represents those absent or unknown values with NULL.
SQL for Files gives you a practical place to learn this behavior. You can open the app in your browser, work through the Learn SQL lessons, and later inspect missing values in your own CSV, JSON, or Parquet files locally with DuckDB WASM.
Beginner rule
NULL does not mean zero, blank text, false, or the word unknown. It means the value is absent or not known.
Why SQL needs NULL
Without NULL, every missing value would need to be disguised as something else. A missing salary might become 0. A missing department might become an empty string. A missing date might become a fake placeholder date. Those shortcuts can make analysis misleading.
- A salary of 0 means the known salary is zero; NULL means the salary is not known.
- An empty string means text is present but blank; NULL means no value was provided.
- A placeholder date can look real; NULL clearly marks that the date is missing.
How to check for NULL correctly
The most important beginner mistake is trying to compare a column to NULL with an equals sign. It looks reasonable, but it does not work the way normal comparisons do.
-- This does not find missing departments
SELECT *
FROM employees
WHERE department = NULL;To find missing values, use IS NULL. To find values that are present, use IS NOT NULL.
SELECT *
FROM employees
WHERE department IS NULL;
SELECT *
FROM employees
WHERE department IS NOT NULL;NULL changes how analysis behaves
NULL values show up again and again as you learn more SQL. Aggregates like SUM and AVG usually ignore NULL values. LEFT JOIN results use NULL when no matching row exists. Grouping and subtotal queries can also use NULL in ways that deserve careful reading.
- COUNT(*) counts rows, including rows that contain NULL values.
- COUNT(column_name) counts only rows where that specific column is not NULL.
- AVG(column_name) usually averages the known values and skips missing ones.
Practice NULL in SQL for Files
The third lesson in the Understanding Data chapter introduces NULL before you move into your first SQL queries. That timing is intentional: missing values are not an advanced edge case. They are part of everyday data work.
- Open the related Missing Values with NULL lesson below.
- Compare NULL with empty strings, zero, and ordinary text values.
- Remember to use IS NULL and IS NOT NULL when you start filtering rows later.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated Learn SQL lessons
Related guides
What Is a Database Table? Rows, Columns, and the Mental Model Behind SQL
Before SQL feels natural, you need one simple mental model: tables are structured collections of records with predictable columns.
SQL Data Types Explained: Text, Numbers, Dates, and Better Questions
Data types are the reason SQL knows the difference between a name, a salary, and a hire date — and that difference shapes every query you write.
Private Local Data Analysis in the Browser
Understand the local processing model behind SQL for Files and how to work safely with sensitive CSV, JSON, and Parquet files.