CodeBlanks Logo Icon CodeBlanks

What is WHERE?

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

query.sql
-- add the condition
SELECT name, price
FROM
WHERE

Sample solution

query.sql
SELECT name, price
FROM products
WHERE price > 10

Expected 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

Question
SELECT name FROM customers
WHERE city ____ 'İstanbul';
Answer
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

All lessons in Beginner