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.