SQL WHERE Clause
The WHERE clause filters records based on a condition.
The WHERE Clause
The WHERE clause is used to filter records — only rows that meet the condition are returned.
Syntax
SELECT column1, column2
FROM table_name
WHERE condition;
Example — Filter by country
SELECT * FROM customers
WHERE country = 'USA';
WHERE with Numbers
Number values do not need quotes:
Example — Filter by age
SELECT * FROM customers
WHERE age > 30;
Operators in WHERE
| Operator | Description | Example |
|---|---|---|
| = | Equal | WHERE age = 25 |
| > | Greater than | WHERE age > 30 |
| < | Less than | WHERE age < 40 |
| >= | Greater than or equal | WHERE age >= 18 |
| != | Not equal | WHERE country != 'USA' |
| BETWEEN | Within a range | WHERE age BETWEEN 20 AND 35 |
| LIKE | Pattern match | WHERE name LIKE 'A%' |
| IN | In a list | WHERE country IN ('USA', 'UK') |
AND, OR, NOT
Example — AND
SELECT * FROM customers
WHERE country = 'USA' AND age > 25;
Example — LIKE (starts with A)
SELECT * FROM customers
WHERE name LIKE 'A%';