Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 02 / Topic 3 of 9

WHERE: asking real questions

WHERE keeps only the rows where a condition is true:

SELECT name, price, stock
FROM products
WHERE price > 500;
     name      |  price  | stock 
---------------+---------+-------
 Laptop Pro 14 | 1200.00 |    15
 Laptop Air 13 |  950.00 |     8
 Phone X       |  799.00 |    25
(3 rows)

The comparison operators: =, <> (not equal — != also works), <, <=, >, >=. SQL's "equals" is a single =:

SELECT first_name, city FROM customers WHERE city = 'Pune';
 first_name | city 
------------+------
 Asha       | Pune
 Vikram     | Pune
(2 rows)

Notice Sara is missing from that result and from city <> 'Pune' — her city is NULL, and NULL compares as "unknown" to everything. Part 3 gives NULL the full lesson it deserves; for now, just notice that rows can quietly sit outside both answers.

Comparisons work on text (alphabetical) and dates (chronological) too:

SELECT first_name, signup_date
FROM customers
WHERE signup_date >= '2025-03-01';
 first_name | signup_date 
------------+-------------
 Sara       | 2025-03-15
 Vikram     | 2025-04-02
(2 rows)

🧪 Quick quiz — answer from memory, then check.

  1. Which rows does WHERE price <> 500 return — and which rows might it silently skip?
  2. How do you write "not equal" in SQL?
Show the answers
  1. Rows whose price is any value other than 500 — but rows where the column is NULL are skipped too, because NULL comparisons are unknown, not true.
  2. <> is the standard spelling; != also works in PostgreSQL.

Done here? The practice set for Part 2 — 8 exercises with solutions — is on the part page.

Search the guide