WHERE
Filter rows based on a condition.
Questions this answers
- →How do I get only the rows I care about?
- →How do I filter by multiple conditions?
- →How do I filter by a range of values?
- →How do I find rows matching a list of values?
How it works
WHERE filters rows before they're returned. Only rows where the condition is TRUE make it into the result. You can combine conditions with AND and OR, use comparison operators, and check against lists with IN.
Basic filter
SELECT name, monthly_listeners FROM artists WHERE genre = 'Pop';
Multiple conditions
SELECT name FROM artists WHERE genre = 'Rock' AND monthly_listeners > 1000000;
💡 AND requires both conditions to be true. OR requires at least one.
Range with BETWEEN
SELECT name FROM artists WHERE monthly_listeners BETWEEN 500000 AND 2000000;
Match a list with IN
SELECT name FROM artists
WHERE genre IN ('Pop', 'Rock', 'Hip-Hop');💡 IN is shorthand for multiple OR conditions on the same column.