Skip to content
/Chapter 3 · Select, Filter, and Sort
Lesson 3.2·garden_shop
Lesson 3.2

SQL WHERE: Filtering Rows

Most of the time you do not want every row, just the ones that matter.

Most of the time you do not want every row in a table. You want the ones that matter. The WHERE clause keeps only the rows that meet a condition, and throws the rest away before they ever reach your results.

It goes right after FROM, and you can compare with =, <, >, and more. Conditions can be combined with AND and OR.

Check filters in small steps

When a WHERE clause has more than one condition, test one condition first, then add the next one. If the result suddenly drops to zero rows, the last condition is the place to inspect.

Text comparisons need quotes, numbers usually do not, and dates should use a clear date format. If a row is missing a value, ordinary comparisons may skip it; later lessons cover SQL NULL handling.

Schema · Garden ShopTable · customers9 columns · 20 rows
Table · customers

One row per customer. Some customers have no phone on file.

9 columns · 20 rows
customer_id intfirst_name textlast_name textemail textphone textcity textstate textsignup_date dateis_active bool
Your task

Return the first name, last name, andstate of every customer from Pennsylvania (PA)who is still active.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: first_name, last_name, state.
  • Rows: 5 active Pennsylvania customers.