CodeBlanks Logo Icon CodeBlanks

IS NULL

Test NULL values with IS NULL and IS NOT NULL.

IS NULL

With IS NULL you check whether a column is empty. = NULL does not work; always use IS NULL for NULL checks.

SELECT name FROM customers
WHERE email IS NULL;

This query customers whose email is empty.

name is selected from customers. WHERE keeps only the rows where email IS NULL holds.

IS NULL — details

NULL means an unknown value; it is not a space or zero. Use IS NOT NULL to filter non-empty rows.

Practice IS NULL

Select names from customers where email is not null.

Starter code

query.sql
-- not null
SELECT name
FROM customers
WHERE

Sample solution

query.sql
SELECT name
FROM customers
WHERE email 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 What is used to check NULL?

  • IS NULL Correct answer
  • == NULL
  • NULL =
  • = NULL

Explanation: IS NULL checks for NULL.

2 Not null

Question
SELECT name FROM customers
WHERE email ____;
Answer
SELECT name FROM customers
WHERE email IS NOT NULL;

Explanation: IS NOT NULL is the right answer.

3 IS NULL: match the terms

Term Meaning
IS NULL empty
IS NOT NULL filled
NULL unknown
= equal

All lessons in Beginner