SQL WHERE
Keep only the rows for which a condition is true.
Syntax
SELECT … FROM … WHERE condition;
Conditions use comparisons (= <> < > <= >=) combined with AND, OR and NOT. Rows where the condition is false or unknown (NULL) are dropped.
Example
Query (on the shop database used in the SQL course)
SELECT name, price FROM products WHERE category = 'Electronics' AND price < 100;
Result
| name | price |
|---|---|
| Wireless mouse | 29.0 |
| USB-C hub | 49.0 |
2 rows
Good to know. Text needs single quotes. Use IS NULL, never = NULL.
Related
Learn it step by step in the free lesson WHERE: Filtering Rows, with exercises that check your queries.