SQL
5 min read
BEGINNER
WHERE and comparisons
Quick AnswerWHERE keeps only rows for which its condition is true. Use it to retrieve a relevant subset of a table without changing stored rows.
Core idea
WHERE keeps only rows for which its condition is true. Use it to retrieve a relevant subset of a table without changing stored rows.
Minimal example
sql
SELECT id, name FROM products WHERE price_cents >= 350 ORDER BY id;Expected SQLite rows:
text
1 | Notebook3 | BagHow it works
Use = for equality, <> for inequality, and >, >=, <, <= for ordered comparisons. A condition follows FROM and precedes ORDER BY. Unknown conditions, including many comparisons with NULL, do not pass WHERE.
Practical example
sql
SELECT id FROM products WHERE price_cents <> 150 ORDER BY id;Expected SQLite rows:
text
134Common mistake and practice
Do not confuse = with assignment. Find products costing at most 150 cents; predict IDs 2 and 4.