SQLPathLab
Basic Query · Basic

WHERE

Filters rows so only records matching a condition are returned.

Overview

WHERE filters source rows before grouping and aggregation, and only rows whose predicate is TRUE continue through the query. Combine predicates with AND, OR, and NOT, using parentheses to make precedence explicit. Test NULL with IS NULL or IS NOT NULL rather than = NULL.

Basic syntax

SELECT * FROM orders WHERE amount > 1000;

Examples

WHERE example

The strict greater-than predicate returns only amounts 1200 and 1500; a row whose amount is exactly 1000 would not satisfy it.

Sample table

Table:orders
orders
idcustomer_idproduct_idnamedepartmentamountstatuscreated_atdiscount
1 101 201 Alice Sales 1200 paid 2026-01-03 0
2 102 202 Bob IT 900 pending 2026-01-08 50
3 101 201 Cindy Sales 1500 paid 2026-02-02 100
4 104 203 David HR 700 cancelled 2026-02-15 0

Run result

result
idcustomer_idproduct_idnamedepartmentamountstatuscreated_atdiscount
1 101 201 Alice Sales 1200 paid 2026-01-03 0
3 101 201 Cindy Sales 1500 paid 2026-02-02 100

Common issues

What is the difference between WHERE and HAVING?

WHERE filters raw rows before grouping, while HAVING filters aggregate results after GROUP BY.

Can WHERE contain multiple conditions?

Yes. Use AND, OR, and NOT. Add parentheses when conditions become complex.

Can WHERE check NULL values?

Yes, but use IS NULL or IS NOT NULL instead of = NULL.

Tags

CommonFiltering

Was this explanation clear?