The MySQL WHERE clause filters table rows so your query only returns, updates, or deletes records matching a logical condition. Without WHERE, a query scans and affects every row in the table.
You can build precise filters by combining standard SQL comparison and range operators. Each predicate evaluates to true, false, or unknown (NULL) for every candidate row:
=), not equal (!=), greater than, less than, greater than or equal, and less than or equal.BETWEEN, or test list and subquery membership with IN and NOT IN.LIKE wildcards or validate text formats using REGEXP.IS NULL and IS NOT NULL.This query filters demo_products to return active items priced above fifty dollars and sorts matching rows from lowest to highest price:
SELECT product_name, price, category
FROM demo_products
WHERE price > 50.00
AND status = 'active'
ORDER BY price ASC;
| product_name | price | category |
|---|---|---|
| Wireless Headphones | 89.99 | Electronics |
| Standing Desk | 299.50 | Furniture |
WHERE YEAR(created_at) = 2026 disables B-tree indexes and causes a full table scan. Rewrite it as a sargable date range with explicit created_at start and end bounds.NULL with =: Writing WHERE deleted_at = NULL always evaluates to unknown and returns zero rows. Always write WHERE deleted_at IS NULL or WHERE deleted_at IS NOT NULL.VARCHAR column against an unquoted integer forces row-by-row type casting and skips indexes. Always quote string literals and keep numeric literals unquoted.WHERE inside UPDATE and DELETE statements?Yes, always include a WHERE clause in UPDATE and DELETE queries unless you intentionally want to modify every row.
FROM, WHERE, and SELECT?MySQL resolves FROM first, filters rows with WHERE, and evaluates column expressions in SELECT afterward.
SELECT alias inside WHERE?Because WHERE runs before SELECT evaluates column aliases, you must repeat the original column or expression in WHERE.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.