EVIKA.ACADEMY›SQL Tutorial
SQL Tutorial›WHERE

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

OperatorMeaningExample
=Equal tocity = 'Noida'
<> or !=Not equal toprice <> 99
>Greater thanprice > 1000
<Less thanstock < 50
>=Greater than or equalprice >= 1000
<=Less than or equalstock <= 100
BETWEENWithin a rangeprice BETWEEN 100 AND 1500
LIKEPattern matchproduct_name LIKE 'W%'
INMatch a listcity IN ('Noida', 'Delhi')
IS NULLValue is missingemail IS NULL

Example 1 — Filter by Text Value

SELECT product_name, category, price
FROM products
WHERE category = 'Electronics';
OUTPUT ↓
product_namecategoryprice
Wireless MouseElectronics899
USB-C HubElectronics1499
HDMI CableElectronics299

Example 2 — Filter by Number

-- Products priced above ₹1000
SELECT product_name, price
FROM products
WHERE price > 1000;
OUTPUT ↓
product_nameprice
USB-C Hub1499
Desk Lamp1199
Ergonomic Chair8999

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_idcustomer_idorder_datetotal_amount
1004C032026-10-058999
1005C042026-10-061499
1006C022026-10-07897
1007C012026-10-08490

Example 4 — Not Equal To

-- All products that are NOT in Electronics
SELECT product_name, category
FROM products
WHERE category <> 'Electronics';
OUTPUT ↓
product_namecategory
Notebook A5Stationery
Ballpoint PensStationery
Desk LampFurniture
Ergonomic ChairFurniture

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;