CodeBlanks Logo Icon CodeBlanks

IS NULL

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

query.sql
-- phone filled
SELECT name
FROM customers
WHERE

Sample solution

query.sql
SELECT name
FROM customers
WHERE phone IS NOT NULL

Expected 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

Question
SELECT name FROM customers
WHERE phone ____;
Answer
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

All lessons in Beginner