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

SQL LIKE: search for a pattern in text

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

The equality operator = only finds identical text. To find the names that start with a letter, the emails that contain a domain or the products that end with a word, you use LIKE with wildcard characters.

Syntax

WHERE column LIKE 'pattern'

How it works

A LIKE pattern can contain two wildcards:

WildcardStands forExampleFinds
%any sequence of characters (even empty)'B%'Benali, Bonnet, B
_exactly one character'_ade'Jade, Wade

The most common patterns: 'abc%' (starts with), '%abc' (ends with) and '%abc%' (contains).

In SQLite, LIKE ignores case for unaccented letters: 'b%' also finds “Bernard”. This behaviour depends on the database: PostgreSQL is case-sensitive (it offers ILIKE), MySQL depends on the collation.

Diagram

clients
prenomnom
LéaBenali
HugoMartin
InèsBonnet
AdamRoux
result
prenomnom
LéaBenali
InèsBonnet
WHERE nom LIKE 'B%': the names that start with B 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. Starts with

The customers whose last name starts with “B”.

SELECT prenom, nom
FROM clients
WHERE nom LIKE 'B%'
LIMIT 8;
Try it in the sandbox
Result
prenomnom
LéaBlanc
SarahBenali
LucasBlanc
LéaBenali
KarimBernard
SarahBlanc
ChloéBonnet
EmmaBernard

8 rows in total

2. Contains

The products whose name contains “de”.

SELECT nom, categorie
FROM produits
WHERE nom LIKE '%de%';
Try it in the sandbox
Result
nomcategorie
Tapis de yogaSport
Gourde inoxSport
Corde à sauterSport
Ballon de footSport
Guide SQLLivres
Livre de cuisineLivres

6 rows in total

3. Ends with

The products whose name ends with “e”.

SELECT nom
FROM produits
WHERE nom LIKE '%e';
Try it in the sandbox
Result
nom
Clavier mécanique
Bougie parfumée
Cafetière
Vase céramique
Raquette
BD aventure
Livre de cuisine
Huile d'olive

8 rows in total

4. One exact character with _

The 4-letter first names that end with “a”.

SELECT DISTINCT prenom
FROM clients
WHERE prenom LIKE '___a';
Try it in the sandbox
Result
prenom
Emma
Lina

2 rows in total

Common mistakes

Forgetting the % wildcard

Without %, LIKE 'B' looks for exactly the text “B” and finds nothing.

Avoid
SELECT * FROM clients WHERE nom LIKE 'B';
Correct
SELECT * FROM clients WHERE nom LIKE 'B%';

Using = with a wildcard

The = sign does not understand wildcards: it literally looks for the % character.

Avoid
SELECT * FROM clients WHERE nom = 'B%';
Correct
SELECT * FROM clients WHERE nom LIKE 'B%';

Searching without the accents

LIKE does not treat “é” as “e”. '%Lea%' does not find “Léa”.

Avoid
SELECT * FROM clients WHERE prenom LIKE 'Lea';
Correct
SELECT * FROM clients WHERE prenom LIKE 'Léa';

Exercises

Try writing the query yourself before opening the solution.

Challenge 1. Show the customers whose email address contains “martin”.

Show a solution
SELECT prenom, nom, email FROM clients WHERE email LIKE '%martin%';
prenomnomemail
SamirMartinsamir.martin2@mail.com
LucasMartinlucas.martin41@mail.com
ThéoMartintheo.martin62@mail.com
HugoMartinhugo.martin75@mail.com
LinaMartinlina.martin82@mail.com
OmarMartinomar.martin100@mail.com
ThéoMartintheo.martin107@mail.com

7 rows in total

Try it in the sandbox

Challenge 2. Show the products whose name starts with “C”.

Show a solution
SELECT nom, prix FROM produits WHERE nom LIKE 'C%';
nomprix
Clavier mécanique15
Casque gaming98
Coussin10.86
Cafetière47.62
Corde à sauter43.19
Café en grains21.79
Chocolat noir22.31

7 rows 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

Is LIKE case-sensitive?

In SQLite, not for unaccented letters. In PostgreSQL, yes (use ILIKE to ignore case). In MySQL, it depends on the column's collation.

How do I search for an actual % character?

With the ESCAPE clause: LIKE '%10\%%' ESCAPE '\' finds the text containing “10%”.

Is LIKE '%word%' slow?

On large tables, yes: a pattern starting with % prevents the use of an index. For advanced text search, databases offer full-text indexes.

Read next