SQL WHERE Clause
Chapter 5 of 40 · Estimated read time: 8 min
The WHERE clause filters rows — only rows where the condition is TRUE are returned. Without WHERE, SELECT returns every row in the table.
Syntax
SELECT column1, column2
FROM table_name
WHERE condition;
Comparison Operators
| Operator | Meaning | Example |
|---|---|---|
| = | Equal to | city = 'Noida' |
| <> or != | Not equal to | price <> 99 |
| > | Greater than | price > 1000 |
| < | Less than | stock < 50 |
| >= | Greater than or equal | price >= 1000 |
| <= | Less than or equal | stock <= 100 |
| BETWEEN | Within a range | price BETWEEN 100 AND 1500 |
| LIKE | Pattern match | product_name LIKE 'W%' |
| IN | Match a list | city IN ('Noida', 'Delhi') |
| IS NULL | Value is missing | email IS NULL |
Example 1 — Filter by Text Value
SELECT product_name, category, price FROM products WHERE category = 'Electronics';
OUTPUT ↓
| product_name | category | price |
|---|---|---|
| Wireless Mouse | Electronics | 899 |
| USB-C Hub | Electronics | 1499 |
| HDMI Cable | Electronics | 299 |
Example 2 — Filter by Number
-- Products priced above ₹1000 SELECT product_name, price FROM products WHERE price > 1000;
OUTPUT ↓
| product_name | price |
|---|---|
| USB-C Hub | 1499 |
| Desk Lamp | 1199 |
| Ergonomic Chair | 8999 |
Example 3 — Filter by Date
-- Orders placed on or after 5th October SELECT order_id, customer_id, order_date, total_amount FROM orders WHERE order_date >= '2026-10-05';
OUTPUT ↓
| order_id | customer_id | order_date | total_amount |
|---|---|---|---|
| 1004 | C03 | 2026-10-05 | 8999 |
| 1005 | C04 | 2026-10-06 | 1499 |
| 1006 | C02 | 2026-10-07 | 897 |
| 1007 | C01 | 2026-10-08 | 490 |
Example 4 — Not Equal To
-- All products that are NOT in Electronics SELECT product_name, category FROM products WHERE category <> 'Electronics';
OUTPUT ↓
| product_name | category |
|---|---|
| Notebook A5 | Stationery |
| Ballpoint Pens | Stationery |
| Desk Lamp | Furniture |
| Ergonomic Chair | Furniture |
WHERE with UPDATE and DELETE
WHERE is not only for SELECT — it is critical in UPDATE and DELETE to avoid modifying every row:
-- Update ONLY the price of product_id = 1 UPDATE products SET price = 999 WHERE product_id = 1; -- Delete ONLY orders before a certain date DELETE FROM orders WHERE order_date < '2026-01-01';
⚠️ Always include WHERE in UPDATE and DELETE. Running
UPDATE products SET price = 0 without a WHERE clause will set every product's price to 0. This is a real, irreversible mistake — always double-check.WHERE evaluates each row independently. For each row in the table, the condition is tested — if TRUE the row is included, if FALSE or NULL it is excluded.
✏️ Practice Exercises
1. Find all products with a price less than or equal to ₹500.
2. Find all customers from Noida.
3. Find all orders with a total_amount greater than ₹2000.
4. Find all products where stock is exactly 200.
Show Answers
-- 1. SELECT * FROM products WHERE price <= 500; -- 2. SELECT * FROM customers WHERE city = 'Noida'; -- 3. SELECT * FROM orders WHERE total_amount > 2000; -- 4. SELECT * FROM products WHERE stock = 200;