SQL Quest
Sign in Français 0 XP Lvl 1
Beginner

SQL WHERE: filter rows

4 min read · 4 runnable examples · updated October 9, 2026

A table often holds thousands of rows, when you only want a few of them: the customers of one city, the products under a given price, the cancelled orders… That is exactly what the WHERE clause does: it only keeps the rows that meet a condition.

Syntax

SELECT columns
FROM table
WHERE condition;

How it works

For each row of the table, SQL evaluates the WHERE condition. If it is true, the row is kept; otherwise, it is discarded.

Comparison operators

OperatorMeaningExample
=equal toville = 'Lyon'
<> or !=not equal tostatut <> 'annulée'
<, >strictly less / greater thanprix < 20
<=, >=less / greater than or equal toage >= 18

Text and dates are written between single quotes ('Paris', '2025-01-01'), numbers without.

Combining several conditions

  • AND: both conditions must be true.
  • OR: at least one of them must be true.
  • NOT: reverses a condition.

AND is evaluated before OR, just like multiplication before addition. As soon as you mix the two, add parentheses to be sure of what your query means.

Diagram

clients
prenomville
LéaLyon
HugoParis
InèsLyon
AdamNantes
result
prenomville
LéaLyon
InèsLyon
WHERE ville = 'Lyon': only the rows that meet the condition are kept.

Simplified diagram to show the idea. The examples below use the real SQL Quest practice database (a fictional online shop: see the full schema).

Glossary: the sample database uses French names
clients
customers
commandes
orders
lignes_commande
order lines
produits
products
fournisseurs
suppliers
employes
employees
prenom / nom
first name / last name (or name)
ville
city
pays
country
prix
price
prix_unitaire
unit price
quantite
quantity
categorie
category
date_commande
order date
poste
job title
departement
department
salaire
salary
statut
status: livrée = delivered, expédiée = shipped, en cours = in progress, annulée = cancelled

Examples with their results

1. A simple condition

The customers who live in Paris.

SELECT prenom, nom, ville
FROM clients
WHERE ville = 'Paris';
Try it in the sandbox
Result
prenomnomville
ZoéLaurentParis
JadeGarciaParis
SarahLambertParis
YanisHaddadParis
ChloéBonnetParis
JadeDuboisParis
LucasDuboisParis
OmarDuboisParis
ClaraLefebvreParis
InèsFontaineParis

13 rows in total · 10 shown

2. Comparing numbers

The products that cost less than €10.

SELECT nom, prix
FROM produits
WHERE prix < 10;
Try it in the sandbox
Result
nomprix
Tapis de yoga6.53
Roman policier8.03
BD aventure9.98
Miel bio3.7

4 rows in total

3. Two conditions with AND

The employees of the IT department who earn more than €4,000.

SELECT prenom, nom, departement, salaire
FROM employes
WHERE departement = 'IT' AND salaire > 4000;
Try it in the sandbox
Result
prenomnomdepartementsalaire
NathanRouxIT6,800
InèsMoreauIT4,500
ClaraGarciaIT5,100

3 rows in total

4. AND and OR with parentheses

The sports or home products that cost less than €15. Without the parentheses, the price condition would only apply to home products.

SELECT nom, categorie, prix
FROM produits
WHERE (categorie = 'Sport' OR categorie = 'Maison') AND prix < 15;
Try it in the sandbox
Result
nomcategorieprix
CoussinMaison10.86
Tapis de yogaSport6.53
Ballon de footSport14.68

3 rows in total

Common mistakes

Forgetting the quotes around text

Without quotes, SQL thinks Paris is a column name and returns the error no such column.

Avoid
SELECT * FROM clients WHERE ville = Paris;
Correct
SELECT * FROM clients WHERE ville = 'Paris';

Mixing AND and OR without parentheses

a OR b AND c is read as a OR (b AND c). The result is often not what you wanted.

Avoid
SELECT * FROM produits WHERE categorie = 'Sport' OR categorie = 'Maison' AND prix < 15;
Correct
SELECT * FROM produits WHERE (categorie = 'Sport' OR categorie = 'Maison') AND prix < 15;

Comparing with = NULL

A missing value (NULL) is equal to nothing, not even to NULL. Use IS NULL (see the lesson on NULL).

Avoid
SELECT * FROM clients WHERE age = NULL;
Correct
SELECT * FROM clients WHERE age IS NULL;

Exercises

Try writing the query yourself before opening the solution.

Challenge 1. Show the orders (all columns) whose status is “annulée” (cancelled).

Show a solution
SELECT * FROM commandes WHERE statut = 'annulée';
idclient_iddate_commandestatutemploye_id
11032023-06-02annulée6
13772024-06-02annulée6
22842023-02-03annulée25
23822023-05-24annulée8
25502024-09-02annulée9
27182024-10-25annulée24
351012025-04-07annulée14
43572025-11-13annulée18

92 rows in total · 8 shown

Try it in the sandbox

Challenge 2. Show the customers from Lyon who are under 30.

Show a solution
SELECT prenom, nom, age FROM clients WHERE ville = 'Lyon' AND age < 30;
prenomnomage
ThéoMichel20

1 row in total

Try it in the sandbox
Want more practice?

The interactive exercises are checked automatically, with a tutor who explains your mistakes. A short lesson stays next to the editor.

Do the interactive exercises

Frequently asked questions

What is the difference between WHERE and HAVING?

WHERE filters rows before they are grouped; HAVING filters groups after a GROUP BY. To filter on a COUNT or a SUM, you need HAVING.

Is WHERE case-sensitive?

With =, text comparison is sensitive to case and accents in SQLite: 'paris' is not equal to 'Paris'. LIKE, on the other hand, ignores case for unaccented letters.

Can I compare two columns?

Yes, for example WHERE prix_unitaire > prix compares two columns of the same row.

How do I write “not equal to”?

With <> (standard SQL) or != (accepted by most databases, including SQLite).

Read next