WHERE makes the database return only rows that meet a condition.
| Operator | Meaning | Example |
|---|---|---|
| = <> < > <= >= | Comparison | price > 500 |
| AND / OR / NOT | Combine conditions | city = 'Cairo' AND ... |
| IN (...) | Within a list | city IN ('Cairo','Giza') |
| BETWEEN a AND b | Between two values (inclusive) | price BETWEEN 100 AND 300 |
| LIKE | Pattern match (% any length, _ one char) | name LIKE 'A%' |
Electronics priced above 500. Open in SQL Lab
IN is cleaner than repeating OR. Open in SQL Lab
Orders from Q1 2026. Open in SQL Lab
Names starting with A. Open in SQL Lab
Parentheses fix the meaning. Open in SQL Lab
For advanced readers Dates and comparison
In SQLite dates are stored as ISO text (YYYY-MM-DD) so comparisons work. PostgreSQL, MySQL and SQL Server have a real DATE type. For time ranges prefer >= start and < the day after the end instead of BETWEEN when times are involved.
Exercise 1 — Show the name and price of Home products priced under 300.
Use AND between two conditions.
Exercise 2 — Show the name and city of customers in Cairo or Alexandria whose name starts with M.
IN for the cities and LIKE 'M%' for the name.
Exercise 3 — Show id and order_date of cancelled orders in 2026.
Use date >= start of 2026 and < start of 2027.
- WHERE filters rows before any grouping.
- IN, BETWEEN and LIKE shorten conditions.
- Use parentheses when mixing AND and OR.
Want an expert to do it for you?
Gomaa Intelligence turns your data into clear reports and decisions. Tell us your problem and we will reply.