Menu
CoddyTech

Missing Values with NULL

Part of the First Queries section of Coddy's PostgreSQL journey. Lesson 8 of 20.

NULL represents a missing or unknown value. It is not zero and it is not an empty string. Ordinary comparisons with NULL produce unknown, so use IS NULL to find missing values.

Input table products:

idnamecategorypricestockactivenote
1Maptravel125TrueNULL
2Notebookbooks80TrueRecycled
3Atlasbooks243FalseNULL
4Mughome128TrueBlue
5lamphome302FalseClearance
6Mini maptravel610TrueNULL
SELECT id, name FROM products WHERE note IS NULL ORDER BY id;

Ids 1, 3 and 6 have no note. Writing note = NULL would not find them: WHERE keeps only true conditions, and equality with an unknown value is not true.

Test missing values with IS NULL or IS NOT NULL, never = NULL.

challenge icon

Challenge

Easy

Return id and note for products that have a note. An empty string still counts as a present note. Order by id.

The input tables are shown in the test panel. Each run starts from fresh data. Return the named columns in the stated order; do not hard-code the displayed rows.

Try it yourself

-- Write your SQL here.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in First Queries

Practice on your own: PostgreSQL playground