Filtering with WHERE
Only the rows you want.
Helen wants to run a sale table at the front of the shop, with books under ten dollars. She doesn't want all thirty books. She only wants the cheap ones. To keep some rows and skip the others, we use a new word. Where.

- A sale table for cheap books
- Not all thirty, just some
- Meet WHERE
Books under ten dollars
Where goes after from. It's followed by a test. Here the test is, price is less than ten. SQL checks that test on every single row, and only keeps the rows where it's true. Run it. Just two books pass the test. Stars Over Lagos, and Garden of Small Things.
SELECT title, price
FROM books
WHERE price < 10;โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโ โ title โ price โ โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโค โ Stars Over Lagos โ 9.99 โ โ Garden of Small Things โ 8.99 โ โโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
How WHERE works
Picture it like this. The rows come in one at a time. Each one meets the test. If the test is true, the row goes through. If it's false, the row is dropped. Select then decides which columns of the surviving rows you see.
The expensive end
The test can point the other way too. Greater than or equal to twenty five finds the most expensive books. Run it. Four books, and three of them are about technology or data. That's a useful thing for Helen to know.
SELECT title, price
FROM books
WHERE price >= 25;โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโ โ title โ price โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโค โ Python for Curious Minds โ 34.99 โ โ SQL in a Weekend โ 29.99 โ โ Spice Roads โ 27.99 โ โ Data for Everyone โ 31.99 โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Summary
Where keeps only the rows that pass a test. You've just answered Helen's sale question. Next, filtering on words instead of numbers, which has one small trap.
Key takeaways- WHERE comes after FROM
- A test runs on every row
- True rows are kept