Ravindra BagaleCourses & study guides Track your progress

4. WHERE: Keep Only the Rows You Need

4.1 Why WHERE Matters (Filter Before You Aggregate)

Why. Totals on the wrong rows mislead managers.

What. WHERE keeps only rows that match a condition — before you sum or average.

How. SELECT … FROM … WHERE condition;

Steps

  1. State the filter in words (city is Pune).
  2. Write WHERE city = 'Pune'.
  3. Then aggregate in later chapters.

Examples

Example 1 · dataset: raja_coffee

SELECT order_id, city, amount_inr
FROM orders
WHERE city = 'Pune'
LIMIT 5;

Output

order_idcityamount_inr
1001Pune840.0
1004Pune1050.0
1006Pune890.0
1009Pune700.0
1013Pune1680.0

Meaning. Only Pune rows — filter before any total.

Ravindra Bagale's Tip

Filter first, aggregate second — muscle memory for clean reports.