SQL WHERE: filter rows with conditions
SELECT picks columns, WHERE picks rows. Only rows where the condition is true come back.
SQL skills · One table
What you will learn
WHERE goes right after the table name. It checks every row against a condition and keeps the ones that pass.
You will filter by text, numbers and dates, and join two conditions with AND or OR.
The basics
WHERE keeps only the rows that pass a condition. It goes right after FROM and the table name.
SELECT customer, amount
FROM invoices
WHERE status = 'Overdue'Text, numbers and dates
Text goes in single quotes and must match the data exactly: 'Overdue'. Numbers have no quotes, no dollar sign and no commas: 5000. Dates are text in the form YYYY-MM-DD, so they go in quotes: '2026-03-01'.
Comparison signs
= equal, <> or != not equal, > more than, < less than, >= at least, <= at most. For dates, later means greater.
Two conditions
WHERE status = 'Open' AND amount > 5000
WHERE status = 'Open' OR amount > 5000AND keeps a row only when both parts are true, so the result gets smaller. OR keeps a row when at least one part is true, so the result gets bigger. When you mix AND and OR, add brackets to make the meaning clear.
Worked examples
Example 1
Every overdue invoice over $5,000.
SELECT customer, amount
FROM invoices
WHERE status = 'Overdue' AND amount > 5000Text in single quotes, the number plain. AND keeps rows that pass both parts.
Example 2
Campaigns that started after March 1, 2026.
SELECT campaign_name, start_date
FROM campaigns
WHERE start_date > '2026-03-01'Dates written as YYYY-MM-DD compare correctly, and later dates are greater.
Reading helps, typing makes it stick. Every task gives you a fresh table, and your query is checked by a real database.
Try a taskCommon mistakes
- Leaving out the quotes: WHERE status = Overdue makes SQL look for a column called Overdue.
- Writing $5,000 in SQL. Numbers have no dollar sign and no commas: 5000.
- Using OR when the request means both. “Overdue and over $5,000” is AND.
Where you will use it at work
- Support: tickets with High priority that are still open.
- Sales: deals in the Proposal stage worth more than $50,000.
- HR: employees hired after a certain date.
Questions people ask
What is the difference between = and LIKE?
= needs an exact match. LIKE matches a pattern, such as names that start with S.
How do I say “not equal”?
Use <> or !=. Both work in the common databases.
Does case matter in text values?
Often yes. PostgreSQL, Oracle and Snowflake treat Paid and paid as different. Copy values exactly as they appear in the data.
Ready to write it yourself?
Practice Filter rows with WHERE