CodeMIRAI
0 XP

Filtering with WHERE

2 min read 5 runnable examples Quiz included

WHERE keeps only the rows that match a condition. It goes after FROM.

SQL
SELECT name, price
FROM products
WHERE price > 100;

Comparison operators

OperatorMeaning
=equal
<> or !=not equal
< >less / greater than
<= >=less / greater than or equal

Note that SQL uses a single = for comparison.

Text values go in single quotes

SQL
SELECT name, city
FROM customers
WHERE country = 'India';

Text comparisons are case-sensitive in SQLite for =, so 'india' would find nothing.

Numbers don't

SQL
SELECT name, stock
FROM products
WHERE stock < 20;

Dates

Dates are stored as text in YYYY-MM-DD form, so they compare correctly as text:

SQL
SELECT order_id, order_date, status
FROM orders
WHERE order_date >= '2024-06-20';

Not equal

SQL
SELECT order_id, status
FROM orders
WHERE status <> 'delivered';
Finished this lesson?Mark it complete to earn +20 XP and move your progress on.