IS NULL
- SQL course
- Beginner
- Lesson 60/115
- 4 min
Find rows with NULL using IS NULL.
IS NULL and IS NOT NULL
IS NULL finds empty rows; IS NOT NULL finds filled ones. = NULL does not work.
SELECT name FROM customers
WHERE phone IS NOT NULL;This query finds customers whose phone was entered.
name is selected from customers. WHERE keeps only the rows where phone IS NOT NULL holds.
IS NULL and IS NOT NULL — details
NULL comparison always returns NULL; that is why = NULL returns no rows. IS NULL or IS NOT NULL is required.
Practice IS NULL and IS NOT NULL
Select names from customers where phone is not null.
Starter code
-- phone filled
SELECT name
FROM customers
WHERESample solution
SELECT name
FROM customers
WHERE phone IS NOT NULLExpected output
name Ayşe Alex
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Not null
SELECT name FROM customers
WHERE phone ____;
SELECT name FROM customers
WHERE phone IS NOT NULL;
Explanation: IS NOT NULL is the right answer.
2 What finds filled rows?
- = NOT NULL
- NOT = NULL
- IS NOT NULL Correct answer
- != NULL
Explanation: IS NOT NULL finds filled rows.
3 IS NULL: match the terms
| Term | Meaning |
|---|---|
IS NULL |
empty |
IS NOT NULL |
filled |
NULL |
unknown |
= |
equal |