Menu
CoddyTech

Filter with WHERE

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

WHERE keeps rows for which a condition is true. A comparison uses a column, an operator and a value. Numbers are unquoted; a text value uses single quotes.

Input table products:

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

Only Atlas and lamp cost more than 20. A price of exactly 20 would be excluded because > means strictly greater. The filter can use a column that is not in the output.

Use WHERE to keep matching rows. = means equal and >= includes the boundary.

challenge icon

Challenge

Easy

Return id and name for products whose stock is zero. 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