Memra

Filtering rows with WHERE

◈ 2 cards

Keep only the rows that match a condition.

Keep the rows you want

WHERE filters rows by a condition — only rows for which it's true come back:

SELECT title, price
FROM books
WHERE genre = 'fiction';

Text literals go in single quotes ('fiction'), never double. Numbers are bare. The usual comparisons all work: =, <> (not equal), <, <=, >, >=.

SELECT title FROM books WHERE price < 12;
titlegenrepriceThe Glass Forestfiction14.99Quantum Morningsscience22.50Rivers of Saltfiction16.00Northern Lightpoetry9.99Bright Hollowfiction13.25genre = 'fiction' keeps 3 of the 10 books.
WHERE chooses rows and keeps every column — the other half of the slice. A row survives only when the condition comes out true.
NORMAL ~/memra/learn/postgresql/where-filtering-rows utf-8 LF