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.

Tip: If 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
We’ll keep using this same table so you can focus on how the 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.

Without WHERE, SQL gives you all the rows. With WHERE, you tell SQL which rows actually matter.

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
The rows for Chris and Evan are removed because they do not meet the condition.

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
!= or <>
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
AND narrows the result. OR broadens the result.

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
Use IN when checking a list of allowed values. Use BETWEEN when checking a range.

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.

Do not write 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.

Missing a WHERE clause in UPDATE or DELETE can affect every row in the table.

Common mistakes

  • using = NULL instead of IS 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
The most expensive beginner mistake is running UPDATE or DELETE without a careful WHERE clause.

Practice questions

1. Return employees with salary above 70000.
2. Return employees in the IT department.
3. Return employees in IT or Sales.
4. Return employees with salary between 60000 and 80000.
5. Return employees whose name starts with A.
6. Return employees whose city is Chicago and whose salary is above 60000.

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.

Quick memory trick: SELECT = what columns, WHERE = what rows.

Related SQL tutorials

SQL Hub
Start here for all SQL topics and tutorials.
SELECT Statement
Learn the base query structure before filtering rows.
ORDER BY
Learn how to sort rows after filtering them.
GROUP BY
Learn how to group filtered rows into summaries.
SQL Query Examples
See broader query patterns that combine SELECT, WHERE, GROUP BY, JOIN, and more.