Quick answer
The WHERE clause filters rows in a SQL query. It tells SQL which rows should stay in the result and which rows should be excluded.
SELECT column_name FROM table_name WHERE condition;
Without WHERE, a query usually returns every row in the table. With WHERE, you only get the rows that match the condition.
SELECT means “what columns do I want?”, then WHERE means “which rows do I want?”
In this guide
Sample table
To keep the examples consistent, imagine this employees table:
| employee_id | name | department | salary | city |
|---|---|---|---|---|
| 1 | Ana | Sales | 62000 | Chicago |
| 2 | Ben | IT | 78000 | Dallas |
| 3 | Chris | HR | 56000 | Chicago |
| 4 | Dana | IT | 85000 | Denver |
| 5 | Evan | Sales | 59000 | Austin |
WHERE clause changes the result.
Why WHERE matters
In real work, you rarely want every row in a table. You usually want a smaller slice of the data:
- employees in one department
- orders above a certain dollar amount
- customers in one city
- records from a certain date range
That is what WHERE is for. It turns a broad query into a useful one.
Basic filtering
The simplest use of WHERE is filtering rows by one condition.
SELECT name, salary FROM employees WHERE salary > 60000;
This returns only employees with salary above 60000.
| name | salary |
|---|---|
| Ana | 62000 |
| Ben | 78000 |
| Dana | 85000 |
Comparison operators
WHERE clauses often use comparison operators. These let you test values against a condition.
Equal to
Greater than
Less than
Greater than or equal to
Less than or equal to
Not equal to
Example:
SELECT name, department FROM employees WHERE department = 'IT';
This returns only IT employees.
| name | department |
|---|---|
| Ben | IT |
| Dana | IT |
AND and OR
You can combine multiple conditions with AND and OR.
Using AND
SELECT name, department, salary FROM employees WHERE department = 'IT' AND salary > 80000;
This returns only rows where both conditions are true.
| name | department | salary |
|---|---|---|
| Dana | IT | 85000 |
Using OR
SELECT name, department FROM employees WHERE department = 'IT' OR department = 'Sales';
This returns rows where either condition is true.
| name | department |
|---|---|
| Ana | Sales |
| Ben | IT |
| Dana | IT |
| Evan | Sales |
IN and BETWEEN
IN and BETWEEN are cleaner shortcuts for common filtering patterns.
Using IN
SELECT name, department
FROM employees
WHERE department IN ('IT', 'Sales');
This is a cleaner version of writing multiple OR checks for the same column.
Using BETWEEN
SELECT name, salary FROM employees WHERE salary BETWEEN 60000 AND 80000;
This returns salaries in that range, inclusive.
| name | salary |
|---|---|
| Ana | 62000 |
| Ben | 78000 |
LIKE text matching
LIKE is used for pattern matching with text.
SELECT name FROM employees WHERE name LIKE 'A%';
This returns names that start with A.
| name |
|---|
| Ana |
Common wildcards:
Any number of characters
One character
LIKE 'A%' means “starts with A.” LIKE '%a' means “ends with a.”
NULL checks
NULL means “no value.” It is not the same as zero, blank text, or false.
SELECT name FROM employees WHERE city IS NULL;
If any rows had no city value, this query would return them.
city = NULL. In SQL, you usually need IS NULL or IS NOT NULL.
WHERE with UPDATE and DELETE
WHERE is not only used with SELECT. It is also critical with UPDATE and DELETE.
UPDATE example
UPDATE employees SET city = 'Boston' WHERE employee_id = 2;
This changes only Ben’s city.
DELETE example
DELETE FROM employees WHERE employee_id = 3;
This deletes only Chris’s row.
Common mistakes
- using
= NULLinstead ofIS NULL - forgetting quotes around text values like
'IT' - confusing AND and OR
- writing conditions that are broader than intended
- forgetting that WHERE is critical in UPDATE and DELETE queries
Practice questions
Bottom line
The WHERE clause is one of the most important parts of SQL because it controls which rows you actually work with.
Once you understand basic conditions, AND, OR, IN, BETWEEN, LIKE, and NULL checks, your queries become much more useful.
Related SQL tutorials
Start here for all SQL topics and tutorials.
Learn the base query structure before filtering rows.
Learn how to sort rows after filtering them.
Learn how to group filtered rows into summaries.
See broader query patterns that combine SELECT, WHERE, GROUP BY, JOIN, and more.