SQL WHERE Clause Explained: Filter Data with Precision

Estimated study time: 7 minutes. The clause that decides which rows make it into your result set.

The WHERE clause is how SQL filters rows before they're returned — instead of pulling an entire table, you tell the database exactly which rows you want.

Basic Syntax

SELECT column1, column2
FROM table_name
WHERE condition;

Comparison Operators

The most common conditions use standard comparison operators: =, <> (or !=), >, <, >=, <=.

SELECT * FROM Employees WHERE Salary > 50000;

Logical Operators

Combine multiple conditions with AND, OR, and NOT:

SELECT * FROM Employees
WHERE Department = 'Sales' AND Salary > 40000;

Pattern Matching with LIKE

Use LIKE with wildcards (% for any sequence of characters, _ for a single character) to filter text loosely:

SELECT * FROM Customers WHERE City LIKE 'New%';

Range and List Filters

BETWEEN filters a range, and IN checks against a list of values:

SELECT * FROM Orders WHERE OrderDate BETWEEN '2026-01-01' AND '2026-03-31';
SELECT * FROM Employees WHERE Department IN ('Sales', 'Marketing');

Handling NULLs

NULL values need IS NULL or IS NOT NULL — comparing with = NULL never returns rows.

SELECT * FROM Employees WHERE ManagerID IS NULL;
💡 Tip: The WHERE clause filters rows before grouping happens. To filter after a GROUP BY (on aggregated values), you need HAVING instead.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with Uncodemy's Data Analytics Course.

Explore Data Analytics Course →