We use IS NULL to check if a value is missing or empty in a database. Using = NULL does not work because NULL means unknown, not a value.
When you want to find records where a column has no value.
When filtering data to exclude or include rows with missing information.
When checking if a user did not provide input in a form stored in the database.
Syntax
SQL
SELECT column_name FROM table_name WHERE column_name ISNULL;
SELECT column_name FROM table_name WHERE column_name = NULL;
IS NULL is the correct way to check for missing values.
= NULL will not work as expected because NULL is not equal to anything, even NULL itself.
Examples
This finds all employees who do not have a manager assigned.
SQL
SELECT * FROM employees WHERE manager_id ISNULL;
This query will return no rows because = NULL does not work for checking NULL.
SQL
SELECT * FROM employees WHERE manager_id = NULL;
This finds all orders that have not been shipped yet.
SQL
SELECT * FROM orders WHERE shipped_date ISNULL;
Sample Program
This creates a table with some values and NULLs, then tries to find rows where value is NULL using both methods.
SQL
CREATETABLE test_null (
id INT,
value VARCHAR(10)
);
INSERTINTO test_null (id, value) VALUES
(1, 'apple'),
(2, NULL),
(3, 'banana');
SELECT id FROM test_null WHERE value ISNULL;
SELECT id FROM test_null WHERE value = NULL;
OutputSuccess
Important Notes
NULL means unknown or missing data, not zero or empty string.
Always use IS NULL or IS NOT NULL to check for NULL values.
Summary
IS NULL checks for missing values correctly.
= NULL does not work and returns no results.
Use IS NULL in your queries to handle NULLs properly.
Practice
(1/5)
1. Which SQL expression correctly checks if a column age has missing (NULL) values?
easy
A. age IS NULL
B. age = NULL
C. age == NULL
D. age != NULL
Solution
Step 1: Understand NULL in SQL
NULL means unknown or missing data, and it cannot be compared with = or != operators.
Step 2: Use IS NULL to check for missing values
The correct way to check for NULL is using IS NULL, which returns true for missing values.
Final Answer:
age IS NULL -> Option A
Quick Check:
Use IS NULL to check missing values [OK]
Hint: Use IS NULL, never = NULL to check missing data [OK]
Common Mistakes:
Using = NULL returns no rows
Confusing IS NULL with equality operator
Using == NULL which is invalid in SQL
2. Which of the following SQL WHERE clauses is syntactically correct to find rows where salary is NULL?
easy
A. WHERE salary IS NULL
B. WHERE salary = NULL
C. WHERE salary == NULL
D. WHERE salary != NULL
Solution
Step 1: Review SQL syntax for NULL checks
SQL uses IS NULL to check for NULL values; equality operators (=, ==) are invalid here.
Step 2: Identify the correct syntax
Only WHERE salary IS NULL is valid and will run without error.
Final Answer:
WHERE salary IS NULL -> Option A
Quick Check:
IS NULL is correct syntax for NULL checks [OK]
Hint: IS NULL is the only valid syntax for NULL checks [OK]
Common Mistakes:
Using = NULL causes syntax errors or no matches
Using == NULL is invalid SQL
Using != NULL does not find NULLs
3. Given the table employees with column manager_id that can be NULL, what will this query return?
SELECT * FROM employees WHERE manager_id = NULL;
medium
A. All rows where manager_id is NULL
B. Syntax error
C. No rows
D. All rows where manager_id is not NULL
Solution
Step 1: Understand comparison with NULL using = operator
In SQL, = NULL does not match any rows because NULL is unknown and cannot be compared with =.
Step 2: Result of the query
The query returns zero rows because no value equals NULL using = operator.
Final Answer:
No rows -> Option C
Quick Check:
= NULL returns no rows [OK]
Hint: = NULL never matches any row, returns empty result [OK]
Common Mistakes:
Expecting = NULL to find NULL values
Confusing NULL with empty string or zero
Assuming syntax error instead of empty result
4. You wrote this query to find rows with NULL in email:
SELECT * FROM users WHERE email = NULL;
But it returns no rows. What is the fix?
medium
A. Use email IS NOT NULL
B. Change to email != NULL
C. Add quotes: email = 'NULL'
D. Change to email IS NULL
Solution
Step 1: Identify incorrect NULL comparison
Using = NULL does not find NULL values because NULL is not equal to anything.
Step 2: Correct NULL check syntax
Use IS NULL to properly find rows where email is missing.
Final Answer:
Change to email IS NULL -> Option D
Quick Check:
Use IS NULL to find missing values [OK]
Hint: Replace = NULL with IS NULL to fix query [OK]
Common Mistakes:
Using != NULL expecting to find NULLs
Using string 'NULL' instead of NULL keyword
Using IS NOT NULL which finds non-missing values
5. You want to select all customers who have no recorded phone number or whose phone number is an empty string. Which WHERE clause correctly finds these rows?
SELECT * FROM customers WHERE ???
hard
A. phone = NULL OR phone = ''
B. phone IS NULL OR phone = ''
C. phone IS NULL AND phone = ''
D. phone = NULL AND phone = ''
Solution
Step 1: Understand NULL and empty string difference
NULL means missing data, empty string means data is present but empty.
Step 2: Combine conditions correctly
Use phone IS NULL to find missing phone numbers and phone = '' to find empty strings, combined with OR to get either case.
Final Answer:
phone IS NULL OR phone = '' -> Option B
Quick Check:
Use IS NULL for missing, = '' for empty [OK]
Hint: Use IS NULL OR = '' to find missing or empty values [OK]
Common Mistakes:
Using = NULL which never matches
Using AND instead of OR excludes all rows
Confusing empty string with NULL
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.