Menu
CoddyTech

Boolean Values

Part of the SQL Foundations section of Coddy's PostgreSQL journey. Lesson 3 of 22.

PostgreSQL has a boolean type whose known values are TRUE and FALSE; a boolean column can also be NULL. A boolean column can serve directly as a WHERE condition.

Input table products:

idnamecategorypricestockactivenote
1Maptravel125TrueNULL
2Notebookbooks80TrueRecycled
3Atlasbooks243FalseNULL
4Mughome128TrueBlue
5lamphome302FalseClearance
6Mini maptravel610TrueNULL
SELECT id FROM products WHERE active ORDER BY id;

The query keeps ids 1, 2, 4 and 6 because their active value is true. False and null do not pass WHERE. IS FALSE explicitly selects known false values.

Use boolean values as conditions. IS FALSE differs from IS NULL.

challenge icon

Challenge

Medium

Return id and name for products that are explicitly inactive. 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 SQL Foundations

Practice on your own: PostgreSQL playground