Stop 03 · Filtering DataTopics · 1/8

WHERE Clause Basics

Part of the SQL Roadmap

In short

Most questions are about some rows, not all of them: orders from Jaipur, payments that failed, students who scored above 80. WHERE is how you keep only the rows that matter.

WHERE keeps only the rows where a condition is true. It runs before grouping and sorting, so it decides which rows the rest of the query ever sees.

The jaadu shakes a round metal sieve over a big steel bowl as fine flour falls through and small stones stay on top.

Think of it like this

Sieving atta

Pour flour through a chalni and only fine atta falls through, while the husk and small stones stay on top. WHERE is the sieve. Every row is tested against your condition, and only rows that pass fall into the result.

Watch it happen

WHERE city = 'Jaipur'

Jaipur ₹850
0
Delhi ₹1,200
1
Jaipur ₹300
2
Kota ₹640
3
Jaipur ₹2,100
4

1/5FROM orders gives every row. WHERE now tests them one by one.

The big ideas

What you need to know

Keeps rows where the condition is TRUE

Each row is checked. FALSE and unknown rows are both thrown away.

Runs early

WHERE runs right after FROM, before SELECT, GROUP BY and ORDER BY. It decides what the rest of the query sees.

Text in single quotes

WHERE city = 'Jaipur'. Numbers need no quotes: WHERE amount > 500.

Text matching can be case-sensitive

In PostgreSQL 'jaipur' does not equal 'Jaipur'. MySQL's default collation ignores case.

See it in code

Walk through the code

sql
1SELECT order_id, city, amount2FROM orders3WHERE city = 'Jaipur';4 5SELECT order_id, status, amount6FROM orders7WHERE status = 'failed'8ORDER BY amount DESC;9 10SELECT name, joined_on11FROM customers12WHERE joined_on >= DATE '2026-01-01';

1/3Keep only Jaipur orders.

Three single-condition filters on text, status and dates. Each runs as is in PostgreSQL and MySQL.

Save yourself the pain

Common mistakes

Oops

WHERE city = "Jaipur" with double quotes in PostgreSQL.

Do this instead

Double quotes mean a column name there. Text values always use single quotes.

Oops

Putting WHERE after ORDER BY.

Do this instead

Clause order is fixed: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.

Your mission

Sieve your data

~15 min

Quick check

Which clause runs first when the database executes a query?

Go deeper

  1. 1Filter a table by a number, a text value and a date.
  2. 2Remember that text and date values need single quotes while numbers do not.
  3. 3Count rows before and after adding a WHERE to see how much it filters.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge