WHERE
ELI5 — The Vibe Check
WHERE is how you filter which rows a query affects. Without WHERE, SELECT returns everything, UPDATE changes everything, DELETE deletes everything. WHERE is basically 'but only if...' in plain English.
Real Talk
WHERE is a SQL clause that filters rows based on a condition or set of conditions. It is evaluated row-by-row before SELECT, UPDATE, or DELETE operations are applied. Conditions can use comparison operators (=, >, <, !=), logical operators (AND, OR, NOT), and functions.
Show Me The Code
-- Multiple conditions
SELECT * FROM orders
WHERE status = 'pending'
AND total > 100
AND created_at > '2024-01-01';
When You'll Hear This
"Add a WHERE clause to filter only active users." / "The WHERE condition is wrong — it's returning too many rows."
Related Terms
DELETE
DELETE removes rows from a table. It is the 'Delete' in CRUD. Like UPDATE, you MUST use a WHERE clause — without it, you delete everything in the table.
HAVING
HAVING is like WHERE but it filters after GROUP BY aggregation. WHERE filters rows before grouping, HAVING filters groups after.
SELECT
SELECT is how you ask a database to give you data. It is the 'Read' in CRUD.
Subquery
A subquery is a query inside a query. The inner query runs first and its result is used by the outer query.
UPDATE
UPDATE changes existing data in a table. It is the 'Update' in CRUD.