Skip to content
BENIBIX Learn

WHERE Clause

Development🗃️ DatabasesDatabase Basics

Also known as WHERE, SQL WHERE, SQL Filter

The part of a SQL command that keeps only the rows that pass a test.

Think of it like

It is like a sieve. Only the rows that pass the test fall through.

Example

Jack only wants this week's orders. He adds WHERE created_at >= '2026-11-09' and gets just those rows.

Why it matters

It decides which rows a command touches. In a DELETE, a missing or wrong WHERE can wipe the wrong data.

Definition

A WHERE clause is the part of a SQL command that picks which rows it works on. It holds a test, like city = 'Paris' or price > 10. Only the rows that pass the test are kept. You can join tests with AND and OR. It works in SELECT to filter what you read, and in UPDATE and DELETE to aim the change.

Example code

sql
SELECT name
FROM customers
WHERE city = 'Paris' AND active = true;
Only customers who live in Paris and are active come back.
WHERE is the first step here. It drops the rows that fail the test.

Common mistake

Testing for an empty value with = NULL. It never matches. Write IS NULL instead.

Key takeaways

  1. 1
    A test per row. Rows that pass are kept.
  2. 2
    AND and OR. Join tests to be more exact.
  3. 3
    Aims changes too. UPDATE and DELETE use it to pick rows.