The SQL WHERE Clause
The WHERE clause filters rows based on a specified condition. Only the rows where the condition evaluates to TRUE are included in the result set. If you are new to SQL, make sure you have completed Chapter 3: SQL SELECT first, as WHERE builds directly on SELECT queries.
SELECT column1, column2, ...
FROM table_name
WHERE condition;
We will use this Employees table for all examples in this chapter:
+----+-----------+------------+--------+-----------+
| ID | Name | Department | Salary | City |
+----+-----------+------------+--------+-----------+
| 1 | Priya K. | Sales | 55000 | Mumbai |
| 2 | John D. | Marketing | 62000 | London |
| 3 | Arun M. | IT | 78000 | Delhi |
| 4 | Emma W. | Sales | 51000 | Sydney |
| 5 | Ravi S. | IT | 72000 | Mumbai |
| 6 | Sara L. | HR | 58000 | New York |
+----+-----------+------------+--------+-----------+
Filter by Text Value
To filter rows where a column matches a specific text value, wrap the value in single quotes:
SELECT Name, Department, Salary
FROM Employees
WHERE Department = 'IT';
+-----------+------------+--------+ | Name | Department | Salary | +-----------+------------+--------+ | Arun M. | IT | 78000 | | Ravi S. | IT | 72000 | +-----------+------------+--------+
Only employees in the IT department are returned. All other rows are excluded.
Filter by Numeric Value
Numeric conditions do not use quotes. You can use comparison operators like =, >, <, >=, and <=:
SELECT Name, Salary
FROM Employees
WHERE Salary > 60000;
+-----------+--------+ | Name | Salary | +-----------+--------+ | John D. | 62000 | | Arun M. | 78000 | | Ravi S. | 72000 | +-----------+--------+
WHERE Comparison Operators
| Operator | Meaning | Example |
|---|---|---|
= |
Equal to | WHERE City = 'Mumbai' |
> |
Greater than | WHERE Salary > 60000 |
< |
Less than | WHERE Salary < 60000 |
>= |
Greater than or equal to | WHERE Salary >= 55000 |
<= |
Less than or equal to | WHERE Salary <= 55000 |
<> or != |
Not equal to | WHERE Department <> 'Sales' |
Example: Not Equal To
SELECT Name, Department
FROM Employees
WHERE Department <> 'Sales';
+-----------+------------+ | Name | Department | +-----------+------------+ | John D. | Marketing | | Arun M. | IT | | Ravi S. | IT | | Sara L. | HR | +-----------+------------+
Example: Less Than or Equal To
SELECT Name, Salary
FROM Employees
WHERE Salary <= 55000;
+-----------+--------+ | Name | Salary | +-----------+--------+ | Priya K. | 55000 | | Emma W. | 51000 | +-----------+--------+
WHERE with Text — Remember the Quotes
⚠️ Critical Rule
Text values in WHERE must be in single quotes: WHERE City = 'Mumbai'. Numbers must not have quotes: WHERE Salary > 60000. Mixing these up is the #1 beginner mistake. You learned this rule in Chapter 2: SQL Syntax.
WHERE with Specific ID
SELECT *
FROM Employees
WHERE ID = 4;
+----+-----------+------------+--------+-----------+ | ID | Name | Department | Salary | City | +----+-----------+------------+--------+-----------+ | 4 | Emma W. | Sales | 51000 | Sydney | +----+-----------+------------+--------+-----------+
WHERE Is Not Just for SELECT
| Statement | What WHERE Does | Example |
|---|---|---|
SELECT ... WHERE |
Filters which rows to retrieve | SELECT * FROM Emp WHERE ID = 1 |
UPDATE ... WHERE |
Filters which rows to modify | UPDATE Emp SET Salary = 60000 WHERE ID = 1 |
DELETE ... WHERE |
Filters which rows to remove | DELETE FROM Emp WHERE ID = 1 |
You will learn UPDATE in Chapter 10 and DELETE in Chapter 11.
💡 Important Warning
Running UPDATE or DELETE without a WHERE clause will affect every row in the table. Always double-check your WHERE condition before executing these statements.
Real-World WHERE Examples
Find employees in Mumbai:
SELECT Name, Salary, City
FROM Employees
WHERE City = 'Mumbai';
+-----------+--------+--------+ | Name | Salary | City | +-----------+--------+--------+ | Priya K. | 55000 | Mumbai | | Ravi S. | 72000 | Mumbai | +-----------+--------+--------+
In the next chapter, you will learn how to combine multiple WHERE conditions using AND, OR, and NOT operators. For sorting your filtered results, see Chapter 7: SQL ORDER BY. For a complete reference of WHERE syntax and operators, see the official MySQL WHERE documentation.
If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Write two queries:
- Find all employees whose salary is exactly 58,000
- Find all employees who do NOT work in Mumbai
SELECT * FROM Employees
WHERE Salary = 58000;
SELECT Name, City
FROM Employees
WHERE City <> 'Mumbai';
Expected Output (Query 2):
+-----------+-----------+ | Name | City | +-----------+-----------+ | John D. | London | | Arun M. | Delhi | | Emma W. | Sydney | | Sara L. | New York | +-----------+-----------+
📝 What You Learned in This Chapter
- The
WHEREclause filters rows that match a specific condition - Text values must be in single quotes; numbers must not have quotes
- Comparison operators:
=,>,<,>=,<=,<> - WHERE works with SELECT, UPDATE, and DELETE statements
- Always use WHERE with UPDATE and DELETE to avoid modifying all rows
Frequently Asked Questions
AND, OR, and NOT operators. This is covered in detail in Chapter 6: SQL AND, OR, NOT.=) for comparison. There is no == in standard SQL. Use <> or != for not equal.📖 Chapter 5 of 30 — SQL Tutorial on Neotech Navigators



