Filtering & Sorting Lesson 4 of 21
SQL WHERE — Filtering Rows
Choose which rows to return with WHERE and comparison operators =, <>, >, <, >= and <=, using numbers and text.
SELECT chooses the columns. WHERE chooses the rows. It's like telling the database: "show me only the products that…".
Syntax
SELECT columns
FROM table
WHERE condition;
Filtering by a number
SELECT name, price
FROM products
WHERE price > 40;
Comparison operators
| Operator | Meaning | Example |
|---|---|---|
= | Equal | category = 'Drinks' |
<> or != | Not equal | status <> 'paid' |
> | Greater than | stock > 100 |
< | Less than | price < 10 |
>= | Greater than or equal | grade >= 9 |
<= | Less than or equal | score <= 80 |
Note that SQL uses a single = to compare, unlike JavaScript and Python which use ==.
Filtering by text
Text values go inside single quotes:
SELECT name, price
FROM products
WHERE category = 'Drinks';
SELECT name, phone
FROM customers
WHERE barangay = 'San Isidro';
Finding problems: out of stock
SELECT name, stock
FROM products
WHERE stock = 0;
SELECT name, stock
FROM products
WHERE stock < 30;
Queries like these are why stores use databases: Aling Nena can see what to restock in one second.
Not equal
SELECT id, customer_id, order_date, status
FROM orders
WHERE status <> 'paid';
Filtering with calculations
The condition can include math:
SELECT name, price, stock, price * stock AS stock_value
FROM products
WHERE price * stock > 2000;
Filtering dates
Dates stored as YYYY-MM-DD text can be compared like text, and the order works correctly:
SELECT *
FROM orders
WHERE order_date >= '2026-11-15';
Case sensitivity
In SQLite, = on text is case-sensitive: 'drinks' won't match 'Drinks'. In MySQL it usually isn't. To be safe, compare lowercase versions:
SELECT name FROM products WHERE LOWER(category) = 'drinks';
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04