The WHERE clause filters which rows a query acts on. Without it, a SELECT returns every row, an UPDATE changes every row, and a DELETE removes every row. With WHERE, you narrow the operation down to only the rows that match a specific condition.
SELECT column1, column2
FROM table_name
WHERE condition;
The same WHERE clause works identically with UPDATE and DELETE.
| id | name | city | age |
|---|---|---|---|
| 1 | Rahim Uddin | Dhaka | 22 |
| 2 | Sara Begum | Chittagong | 20 |
| 3 | Karim Ali | Sylhet | 23 |
| 4 | Nila Akter | Dhaka | 21 |
| 5 | Rafi Hossain | Rajshahi | 24 |
The WHERE clause supports these comparison operators:
| Operator | Meaning | Example |
|---|---|---|
= | Equal to | WHERE city = 'Dhaka' |
!= or <> | Not equal to | WHERE city != 'Dhaka' |
> | Greater than | WHERE age > 21 |
< | Less than | WHERE age < 23 |
>= | Greater than or equal | WHERE age >= 22 |
<= | Less than or equal | WHERE age <= 21 |
String values must be wrapped in single quotes. The comparison is case-insensitive by default in MySQL:
-- Exact match on city
SELECT * FROM students WHERE city = 'Dhaka';
| id | name | city | age |
|---|---|---|---|
| 1 | Rahim Uddin | Dhaka | 22 |
| 4 | Nila Akter | Dhaka | 21 |
-- Rows where city is NOT Dhaka
SELECT * FROM students WHERE city != 'Dhaka';
Numbers do not need quotes:
-- Students older than 21
SELECT name, age FROM students WHERE age > 21;
| name | age |
|---|---|
| Rahim Uddin | 22 |
| Karim Ali | 23 |
| Rafi Hossain | 24 |
Dates must be wrapped in single quotes and written in YYYY-MM-DD format:
-- Orders placed after a specific date
SELECT * FROM orders WHERE order_date > '2025-01-01';
-- Records from exactly one date
SELECT * FROM orders WHERE order_date = '2025-06-15';
The WHERE clause works identically in UPDATE and DELETE:
-- Update only Karim Ali's row
UPDATE students SET city = 'Barishal' WHERE id = 3;
-- Delete only students under 21
DELETE FROM students WHERE age < 21;
WHERE in your UPDATE and DELETE statements. Without it, the operation applies to every row in the table.
WHERE filters rows before the query acts on them — only matching rows are returned, updated, or deleted.YYYY-MM-DD format.!= and <> mean "not equal to" — they are interchangeable.WHERE works the same way in SELECT, UPDATE, and DELETE.WHERE clause.
WHERE city = NULL never matches anything, even for rows where city is genuinely NULL — you must use WHERE city IS NULL instead.
WHERE order_date = 2025-06-15 is parsed as arithmetic (2025 minus 6 minus 15), not a date — always quote dates as '2025-06-15'.
WHERE city = 'dhaka' matches 'Dhaka' too — this surprises developers coming from case-sensitive languages.
A second example — filtering on two different column types in a single WHERE clause using AND:
SELECT name, city, age
FROM students
WHERE city = 'Dhaka' AND age >= 21;
Q: How do I check if a value is NULL?
A: Use WHERE column IS NULL or WHERE column IS NOT NULL — the standard = operator never matches NULL values.
Q: Can WHERE filter on a range of values?
A: Yes — use BETWEEN for ranges (WHERE age BETWEEN 18 AND 25) or IN for a specific list (WHERE city IN ('Dhaka', 'Sylhet')).
Q: Is WHERE case-sensitive for text comparisons?
A: It depends on the column's collation — most default collations are case-insensitive. See the official WHERE clause optimization docs for how MySQL evaluates conditions.