TutorialsSQLWHERE Clause
🟢 Free Demo
SQL TutorialTopic 3 of 20

WHERE Clause

Filter rows based on a condition

✅ What You Will Learn

How WHERE filters rows based on a condition
How to use comparison operators: =, <>, >, <, >=, <=
How to filter text, numbers, and dates
How BETWEEN works for range filters
How LIKE works for partial text matching
How to combine WHERE with SELECT effectively

The WHERE clause filters the rows returned by a SELECT query. Without WHERE, SQL returns every row in the table. With WHERE, it returns only the rows that match your condition.

This is how you answer specific business questions: "Show me only orders above ₹10,000" or "Show me only customers from Delhi" — these filters go in the WHERE clause.

WHERE evaluates each row one by one and only includes it in the result if the condition is true.

📋 The orders table used in examples

order_idcustomer_nameproductamountcity
1001Rahul SharmaLaptop45000Delhi
1002Priya VermaMobile Phone18000Noida
1003Amit KumarHeadphones3500Gurgaon
1004Sneha KapoorLaptop52000Delhi
1005Vikram SinghTablet28000Noida

Syntax

SQL SYNTAX
SELECT column1, column2
FROM table_name
WHERE condition;

Examples

Example 1Filter by a number
SELECT customer_name, product, amount
FROM orders
WHERE amount > 20000;
OUTPUT
customer_name | product | amount
--------------|---------|-------
Rahul Sharma  | Laptop  | 45000
Sneha Kapoor  | Laptop  | 52000
💡

Only rows where amount is greater than 20000 are returned.

Example 2Filter by text (use single quotes)
SELECT *
FROM orders
WHERE product = 'Laptop';
OUTPUT
order_id | customer_name | product | amount | order_date
---------|---------------|---------|--------|------------
1001     | Rahul Sharma  | Laptop  | 45000  | 2026-01-15
1004     | Sneha Kapoor  | Laptop  | 52000  | 2026-01-17
💡

Text values must be wrapped in single quotes. SQL is case-sensitive for text comparisons in most databases.

Example 3Filter by date
SELECT customer_name, order_date
FROM orders
WHERE order_date = '2026-01-16';
OUTPUT
customer_name | order_date
--------------|------------
Priya Verma   | 2026-01-16
Amit Kumar    | 2026-01-16
Example 4Comparison operators
-- Equal to
WHERE amount = 45000

-- Not equal to
WHERE product <> 'Laptop'

-- Greater than or equal
WHERE amount >= 18000

-- Less than
WHERE amount < 10000

-- Between two values (inclusive)
WHERE amount BETWEEN 10000 AND 50000

📌 Key Points to Remember

  • WHERE goes after FROM in the query
  • Text values need single quotes — numbers do not
  • Use = for equality, <> or != for not equal
  • BETWEEN is inclusive — BETWEEN 10 AND 20 includes 10 and 20
  • Dates should be written in YYYY-MM-DD format for safe comparisons

🏢 Real-World Application

WHERE is the clause that makes SQL useful for business questions. "Find all customers who placed orders above ₹50,000 in December 2025" — that is a WHERE clause. "List all employees in the Delhi office who joined after 2023" — WHERE again. At companies like Amazon India or Swiggy, analysts use WHERE every single day to narrow down millions of rows to the specific subset they need for a report. BETWEEN is commonly used for date ranges — WHERE order_date BETWEEN '2026-01-01' AND '2026-01-31' — to pull monthly data. LIKE is used for text searches — WHERE city LIKE '%Delhi%' — to find partial matches in customer addresses.

⚠️ Common Mistakes to Avoid

WRONGUsing double quotes for text values: WHERE product = "Laptop"
FIXSQL requires single quotes for text: WHERE product = 'Laptop'. Double quotes are used for column or table names in some databases, not for values.
WRONGWriting WHERE before FROM
FIXSQL clause order is fixed: SELECT → FROM → WHERE → ORDER BY. Writing WHERE before FROM causes a syntax error.
WRONGUsing = with NULL values
FIXNULL cannot be compared with =. WHERE column = NULL always returns no rows. Use WHERE column IS NULL instead.
✏️Test Yourself

Which SQL clause is used to filter records?

❓ Frequently Asked Questions

What does the WHERE clause do in SQL?

WHERE filters rows returned by a query. It evaluates each row against a condition and only includes rows where the condition is true. It is used after FROM and before ORDER BY.

What is the difference between WHERE and HAVING in SQL?

WHERE filters individual rows before grouping. HAVING filters groups after GROUP BY has been applied. You cannot use aggregate functions like SUM() or COUNT() in a WHERE clause — use HAVING for that.

How do I filter dates in SQL WHERE clause?

Use the YYYY-MM-DD format for date comparisons: WHERE order_date = '2026-01-15'. For ranges, use BETWEEN: WHERE order_date BETWEEN '2026-01-01' AND '2026-01-31'.

What is LIKE in SQL WHERE clause?

LIKE is used for partial text matching. The % wildcard means zero or more characters. WHERE name LIKE 'R%' finds names starting with R. WHERE city LIKE '%Delhi%' finds any city containing Delhi.

Can WHERE have multiple conditions?

Yes. Use AND to require both conditions to be true, OR to require at least one to be true. Example: WHERE amount > 10000 AND city = 'Delhi' returns only high-value orders from Delhi.

✏️ Practice Exercise

Write a query to find all orders where the amount is between ₹5,000 and ₹20,000.

← PreviousSELECT StatementNext →AND, OR, NOT
🎓 Level Up Faster

Learn SQL with Live Trainer Guidance

These tutorials give you the theory. Our live SQL course at EVIKA Academy, Noida teaches you to apply SQL on real company datasets — with a trainer who uses it daily at MakeMyTrip.