Filtering with WHERE
Site Admin
· 11 Sep 2026
· 2 views
Narrowing the Result Set
WHERE filters rows before you see them. Only rows for which the condition is true come back.
SELECT * FROM customers WHERE city = 'Mumbai';
SELECT * FROM customers WHERE id >= 100;
SELECT * FROM customers WHERE is_active = TRUE;Comparison Operators
=,<>or!=for equality/inequality.>,<,>=,<=for ordering.- Beware: comparing to NULL is special (see below).
Combining Conditions
SELECT * FROM customers
WHERE city = 'Mumbai' AND is_active = TRUE;
SELECT * FROM customers
WHERE city = 'Mumbai' OR city = 'Pune';
SELECT * FROM customers
WHERE is_active = TRUE AND (city IN ('Mumbai', 'Pune') OR created_at > '2024-01-01');AND and OR combine conditions; use parentheses to control precedence the same way as math.
Operators That Read Well
SELECT * FROM customers WHERE id IN (1, 2, 3);
SELECT * FROM customers WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31';
SELECT * FROM customers WHERE name LIKE 'A%'; -- starts with A
SELECT * FROM customers WHERE name LIKE '_iya'; -- any char then 'iya'
SELECT * FROM customers WHERE city IS NULL; -- never use = NULLKey Points
- WHERE filters rows before the results show.
- Combine conditions with AND / OR and parentheses.
- IN, BETWEEN, LIKE and IS NULL are everyday tools.
- NULL comparisons need IS NULL, never = NULL.