WHERE filters rows before they're returned — only rows matching the condition make it into the result.
Syntax
SELECT columns
FROM table_name
WHERE condition;
Sample Table: employees
| id | name | department | salary |
|---|---|---|---|
| 1 | Aman | Engineering | 65000 |
| 2 | Riya | Marketing | 52000 |
| 3 | Karan | Engineering | 71000 |
Example
SELECT name, salary
FROM employees
WHERE salary > 60000;
Output:
| name | salary |
|---|---|
| Aman | 65000 |
| Karan | 71000 |
Comparison Operators
| Operator | Meaning |
|---|---|
| = | equal to |
| <> or != | not equal to |
| >, < | greater than, less than |
| >=, <= | greater than or equal, less than or equal |
Combining Conditions
SELECT name FROM employees
WHERE department = 'Engineering' AND salary > 60000;
See AND / OR for combining multiple conditions in detail.
Practical Use Case
Almost every real query has a WHERE clause — active users only, orders from this month, products in stock. It's the difference between "all the data" and "the data that actually answers the question."
Common Mistakes
- Confusing
WHERE(filters individual rows, runs before grouping) with HAVING (filters grouped results, runs after grouping) — see WHERE vs HAVING - Using
=to compare againstNULL— this never matches; use IS NULL instead - Forgetting quotes around string/date literals:
WHERE department = Engineeringis invalid — it must be'Engineering'
Interview Relevance
Filtering logic shows up in nearly every SQL interview question. Interviewers are often less interested in the syntax and more in whether you correctly translate a business requirement ("active customers who spent over ₹10,000 last quarter") into the right conditions.
Practice Question
Write a query to find all employees in the "Marketing" department earning less than 55,000.