0
Challenge · 08SQL I: Asking Questions of Data
WHERE & the operator vocabulary
SQLused in ~100% of apps
Your DevLog homepage is about to grow a search box. Type "postgres" and the feed should narrow to just the matching posts — and it must never, under any phrasing, show bob's private draft to a stranger. Both of those are WHERE clauses. One is a feature; the other, written carelessly, is the security bug that gets a company in the news.
Core idea. A WHERE clause is a boolean expression evaluated once per row, and only rows where it evaluates to true survive. Every operator you learn here — =, <>, <, >, BETWEEN, LIKE/ILIKE, IN — is just a different way of computing that one true/false answer. Combine tests with AND, OR and NOT, but know that AND binds tighter than OR: an unparenthesized mix of the two is the single most common way a query returns rows it should never have shown.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
where like_count >= 30
| title | owner | public | likes | verdict | kept? |
|---|---|---|---|---|---|
| Why I switched to Postgres | alice | true | 42 | true | kept |
| RLS notes (draft) | alice | false | 0 | false | dropped |
| Ships on Fridays | bob | true | 17 | false | dropped |
| Secret roadmap (draft) | bob | false | 3 | false | dropped |
| Indexing tips for Postgres | alice | true | 88 | true | kept |
| My Vim setup | bob | true | 5 | false | dropped |
returns2 rows
The six comparison operators — =, <>, <, >, <=, >= — each yield true or false for every row. Two posts clear 30 likes.
The one rule under all of it: a
WHERE clause keeps a row only when its expression is true. false drops the row, and so does NULL— "unknown" is not "true". Every operator on this page is just a different way of computing that one verdict.↑ play a little first, then dig in