SQL Tutorial

SQL NULL Values – IS NULL and IS NOT NULL with Examples (2026-27)

In SQL, a NULL value represents missing, unknown, or absent data in a database field. NULL is not the same as zero, not the same as an empty string '', and not the same as false — it literally means no value was recorded. Understanding NULL is critical because standard comparison operators like = and != do not work with NULL — you must use the special IS NULL and IS NOT NULL operators. In this beginner-friendly guide you will learn what NULL means, how to find and filter NULL values, how to update NULLs, how COALESCE replaces NULL with a default, and the most important mistakes to avoid.



✅ What is NULL in SQL?

✅ NULL means a field has no value — the data is missing, unknown, or was never entered.

✅ NULL is not zero, not empty string, and not false — it is the complete absence of a value.

✅ Any comparison with NULL using =, !=, <, or > returns UNKNOWN — not TRUE or FALSE.

💡 Real-world example: A new employee joins but their phone number is not known yet. The Phone column for that employee is stored as NULL — not zero, not blank, just absent. Later you can UPDATE it once the number is provided.

Sample Employees Table (with NULL values shown in red):-

Employees
IDNameDepartmentSalaryPhone
1ANNIIT100009876543210
2POOJAIT90000NULL
3RAJHR50009123456789
4SUJANHR8000NULL
5MEENASales120009988776655

POOJA (ID=2) and SUJAN (ID=4) have no phone number recorded — their Phone column is NULL.


✅ IS NULL and IS NOT NULL Syntax

-- Find rows where the column IS NULL (missing value):
SELECT column1, column2, ...
FROM table_name
WHERE column_name IS NULL;

-- Find rows where the column IS NOT NULL (has a value):
SELECT column1, column2, ...
FROM table_name
WHERE column_name IS NOT NULL;

IS NULL:- Returns rows where the column has no value.

IS NOT NULL:- Returns rows where the column has a value.

🚨 Critical Rule: NEVER use = NULL or != NULL — these always return no rows because NULL cannot be compared with standard operators. Always use IS NULL or IS NOT NULL.

✅ Example 1 – Find Rows with NULL (IS NULL)

Find all employees whose phone number is missing.

SELECT Query:-

SELECT * FROM Employees
WHERE Phone IS NULL;

Result:-

Result — Employees with No Phone Number
IDNameDepartmentSalaryPhone
2POOJAIT90000NULL
4SUJANHR8000NULL
💡 Use case: IS NULL is used in data quality checks — finding incomplete records that need to be filled in. Running this query every week shows which employees still haven't provided their phone numbers.

✅ Example 2 – Find Rows without NULL (IS NOT NULL)

Find all employees who have a phone number recorded.

SELECT Query:-

SELECT * FROM Employees
WHERE Phone IS NOT NULL;

Result:-

Result — Employees with Phone Numbers
IDNameDepartmentSalaryPhone
1ANNIIT100009876543210
3RAJHR50009123456789
5MEENASales120009988776655
ℹ️ Use case: IS NOT NULL is used to retrieve only complete, usable records — for example, sending SMS notifications only to employees who have a phone number on file.

✅ Example 3 – Update NULL Values

Update POOJA's phone number (previously NULL) to a real number.

UPDATE Query:-

UPDATE Employees
SET Phone = '9000000001'
WHERE ID = 2;

Result — After Update:-

Employees — POOJA's Phone Updated
IDNameDepartmentSalaryPhone
1ANNIIT100009876543210
2POOJAIT900009000000001
3RAJHR50009123456789
4SUJANHR8000NULL
5MEENASales120009988776655
💡 Also useful: You can set a value back to NULL using SET Phone = NULL WHERE ID = 4. This clears the phone number for SUJAN, making the field NULL again.

✅ Example 4 – COUNT with NULL Values

Understanding how NULL affects COUNT() is essential for accurate reporting.

SELECT Query:-

-- COUNT(*) counts ALL rows including NULLs:
SELECT COUNT(*) AS TotalEmployees FROM Employees;

-- COUNT(column) counts only NON-NULL values:
SELECT COUNT(Phone) AS EmployeesWithPhone FROM Employees;

Result:-

Result — COUNT Comparison
QueryResult
COUNT(*)5
COUNT(Phone)3
ℹ️ Explanation: COUNT(*) returns 5 — all rows. COUNT(Phone) returns 3 — only ANNI, RAJ, and MEENA have non-NULL phone numbers. POOJA and SUJAN's NULLs are automatically ignored by COUNT(column).

✅ Example 5 – COALESCE: Replace NULL with a Default Value

COALESCE returns the first non-NULL value from a list of arguments — perfect for displaying a fallback when a column is NULL.

SELECT Query:-

SELECT Name,
       COALESCE(Phone, 'Not Provided') AS PhoneNumber
FROM Employees;

Result:-

Result — NULL Replaced with 'Not Provided'
NamePhoneNumber
ANNI9876543210
POOJANot Provided
RAJ9123456789
SUJANNot Provided
MEENA9988776655
💡 SQL Server alternative: ISNULL(Phone, 'Not Provided') works the same way in SQL Server — returns 'Not Provided' when Phone is NULL. COALESCE is the standard SQL version that works across all databases.

✅ NULL vs Empty String vs Zero

ConceptNULLEmpty String ('')Zero (0)
MeaningNo value / unknownValue entered but blankNumeric value of zero
Data typeAnyText (VARCHAR)Numeric (INT, etc.)
IS NULL checkTRUEFALSEFALSE
= '' checkUNKNOWNTRUEError / FALSE
= 0 checkUNKNOWNError / FALSETRUE
In COUNT(col)Not countedCountedCounted
⚠️ Key distinction: WHERE Phone = '' and WHERE Phone IS NULL are completely different queries. Empty strings and NULLs are stored and behave differently — never confuse them.

✅ How NULL Affects Aggregate Functions

FunctionHandles NULL?Behaviour
COUNT(*)✅ Counts NULLsCounts all rows regardless of NULLs
COUNT(column)❌ Skips NULLsCounts only non-NULL values in that column
SUM(column)❌ Skips NULLsAdds only non-NULL values; NULL treated as 0
AVG(column)❌ Skips NULLsCalculates average of non-NULL values only
MAX(column)❌ Skips NULLsReturns maximum of non-NULL values
MIN(column)❌ Skips NULLsReturns minimum of non-NULL values
ℹ️ Important for AVG: If a column has 5 rows but 2 are NULL, AVG divides by 3 (non-NULL count), not 5 (total rows). This can make the average higher than you might expect — always be aware of NULLs in numeric columns.

✅ Key Points to Remember

✅ NULL = missing or unknown data — not zero, not empty string.

✅ Use IS NULL — to find rows with no value in a column.

✅ Use IS NOT NULL — to find rows that have a value in a column.

✅ Never use = NULL or != NULL — always returns no results (UNKNOWN).

✅ COALESCE(col, 'default') — replaces NULL with a fallback value in SELECT output.

✅ COUNT(*) includes NULLs — COUNT(column) skips NULLs.

✅ SUM, AVG, MAX, MIN all ignore NULLs — only non-NULL values are used.

✅ NULL in NOT IN list — can cause the entire NOT IN query to return zero rows.


✅ Common SQL NULL Mistakes to Avoid

❌ Mistake 1: Using = NULL instead of IS NULL
Wrong: WHERE Phone = NULL — always returns zero rows.
Correct: WHERE Phone IS NULL — the only way to find NULL values.
❌ Mistake 2: Using != NULL instead of IS NOT NULL
Wrong: WHERE Phone != NULL — always returns zero rows.
Correct: WHERE Phone IS NOT NULL.
❌ Mistake 3: Confusing NULL with empty string
WHERE Phone = '' finds rows with empty strings — NOT NULL rows. These are completely different storage types. Always check which one your data contains before filtering.
❌ Mistake 4: NULL in a NOT IN list
WHERE Department NOT IN ('IT', NULL) returns zero rows — NULL in a NOT IN list breaks the entire comparison. Always ensure your NOT IN list has no NULLs. Use IS NOT NULL as an additional filter if needed.

✅ Frequently Asked Questions (FAQ)

What is NULL in SQL?
NULL in SQL means the absence of any value — missing or unknown data. It is not the same as zero, empty string, or false. NULL represents a field that has no recorded value whatsoever.
How do I check for NULL values in SQL?
Use IS NULL: WHERE column_name IS NULL returns rows where the column has no value. Use IS NOT NULL: WHERE column_name IS NOT NULL returns rows where the column has a value. Never use = NULL or != NULL.
Why can't I use = NULL in SQL?
Because NULL represents unknown data, comparing an unknown value with anything (even another NULL) always returns UNKNOWN — not TRUE or FALSE. SQL therefore requires IS NULL or IS NOT NULL to correctly test for the presence or absence of values.
What is the difference between NULL and empty string in SQL?
NULL means no value was ever entered — the field is completely absent. An empty string '' means a value was entered but it was blank. They behave very differently: NULL IS NULL returns TRUE, but '' IS NULL returns FALSE.
How do I replace NULL with a default value in SQL?
Use COALESCE: SELECT COALESCE(Phone, 'Not Provided') FROM Employees returns 'Not Provided' for any row where Phone is NULL. In SQL Server, ISNULL(Phone, 'Not Provided') works the same way.
How does NULL affect SQL aggregate functions?
Most aggregate functions (SUM, AVG, MAX, MIN, COUNT with column name) automatically ignore NULL values. COUNT(*) counts all rows including NULLs. COUNT(column) only counts non-NULL values in that column — an important difference for accurate reporting.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.