What is WHERE?
- SQL course
- Beginner
- Lesson 7/115
- 4 min
Learn to filter rows by a condition with WHERE.
What is WHERE?
The WHERE clause filters rows in a query by a condition. Only rows that meet the condition are returned.
SELECT name, price
FROM products
WHERE price > 10;This returns only products whose price is greater than 10. WHERE comes after FROM and before ORDER BY.
name, price is selected from products. WHERE keeps only the rows where price > 10 holds.
What is WHERE? — details
WHERE is the heart of the query; it keeps rows whose condition evaluates to true. The condition combines columns, constants and operators. Only matching rows appear in the result.
For example, WHERE city = 'İzmir' returns only customers in İzmir; without WHERE every row of the table is returned.
Practice What is WHERE?
Select name and price from products where price is greater than 10.
Starter code
-- add the condition
SELECT name, price
FROM
WHERESample solution
SELECT name, price
FROM products
WHERE price > 10Expected output
name price Defter 12 Çanta 25
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Where does WHERE go?
- Before FROM
- Before SELECT
- After FROM Correct answer
- At the very end
Explanation: WHERE comes after FROM.
2 Equality condition
SELECT name FROM customers
WHERE city ____ 'İstanbul';
SELECT name FROM customers
WHERE city = 'İstanbul';
Explanation: SQL uses a single = for equality; text values go in single quotes.
3 What is WHERE: match the terms
| Term | Meaning |
|---|---|
= |
equal |
<> |
not equal |
< |
less than |
> |
greater than |