lesson 03 Filtering & sorting · beginner
Filter with WHERE
Keep only rows that meet a condition.
the idea
WHERE keeps rows for which a condition is true. Text values need single quotes; column names do not. Rows whose comparison evaluates to NULL are not kept.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
customers4 columns · 8 rows
| idinteger · key | nametext | citytext | joined_attext |
|---|---|---|---|
| 1 | Alice | Chicago | 2024-01-10 |
| 2 | Ben | Austin | 2024-02-12 |
| 3 | Cara | Seattle | 2024-03-05 |
| 4 | Dev | Chicago | 2024-04-20 |
| 5 | Elena | NULL | 2024-05-01 |
showing 5 of 8 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
SELECT name, city FROM customers WHERE city = 'Chicago';
Watch for: SQL uses = for equality. City names are string values, so quote them.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Start with customers. Chicago and Austin are values, not column names.
step-1.sqlSELECT name,city FROM customers;
Keep matching rows. WHERE keeps true comparisons. Missing city values do not match.
step-2.sqlSELECT name,city FROM customers WHERE city='Chicago';