Fundamentals

The SQL WHERE Clause: Filtering Data with Every Operator

8 min read · Updated August 13, 2026

SELECT tells the database which columns you want. WHERE tells it which rows qualify. It goes right after FROM (and before GROUP BY, if you use one), and every example below runs against the Employees table in the SQL Playground.

Comparison operators

OperatorMeaning
=equal to
<> or !=not equal to
> / <greater than / less than
>= / <=greater than or equal / less than or equal
SELECT first_name, salary
FROM Employees
WHERE salary >= 100000;

Combining conditions: AND, OR, NOT

AND requires both sides to be true; OR requires at least one. When you mix them, use parentheses — AND is evaluated before OR, which trips people up:

-- Active employees who are either in Engineering (10) OR earn over 120k
SELECT first_name, dept_id, salary
FROM Employees
WHERE active = 1
  AND (dept_id = 10 OR salary > 120000);

Without the parentheses, active = 1 AND dept_id = 10 OR salary > 120000 would also return inactive employees who happen to earn over 120k — probably not what you meant.

Matching a list with IN

Instead of chaining several ORs, use IN to check against a list of values:

SELECT first_name, dept_id
FROM Employees
WHERE dept_id IN (10, 20, 30);

Add NOT to invert it: WHERE dept_id NOT IN (10, 20, 30).

A range with BETWEEN

BETWEEN is inclusive on both ends — the boundary values themselves are included in the result:

SELECT first_name, salary
FROM Employees
WHERE salary BETWEEN 70000 AND 100000;

Pattern matching with LIKE

LIKE matches text patterns using two wildcards: % (any number of characters, including zero) and _ (exactly one character).

WHERE email LIKE '%@example.com'   -- ends with this domain
WHERE first_name LIKE 'A%'         -- starts with A
WHERE first_name LIKE '%an%'       -- contains "an" anywhere

Checking for missing values with IS NULL

This is the mistake almost every beginner makes at least once: you cannot test for NULL with = NULL. NULL means "unknown," and in SQL's three-valued logic, unknown compared to anything — even another NULL — is never true.

-- Wrong: this returns zero rows, even if manager_id has NULLs
SELECT * FROM Employees WHERE manager_id = NULL;

-- Correct
SELECT * FROM Employees WHERE manager_id IS NULL;
SELECT * FROM Employees WHERE manager_id IS NOT NULL;

WHERE vs HAVING

WHERE filters individual rows before any grouping happens. If you need to filter based on an aggregate result (like "departments with more than 5 employees"), you need HAVING instead — see our dedicated guide on GROUP BY vs HAVING.

Try it yourself

Every WHERE clause above runs directly against the pre-loaded Employees table in the Playground.

Open the Playground

Related reading