Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.1: Finding patterns with LIKE and wildcards

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

50 minutes

You only remember the start

A pupil asks for "the chee-something". It could be a cheese roll or a cheese toastie.

You cannot test for an exact name you do not know. A pattern can stand for many names at once.

Key words

WordWhat it means
Databasean organised store of tables that you can ask questions
LIKEtests whether text matches a pattern
Patterntext with wildcards that stands for many possible words
Wildcarda special mark that stands for other characters
Many-character wildcardthe symbol `%`: any number of characters, even none
One-character wildcardthe symbol `_`: exactly one character
Characterone letter, digit, space or symbol

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can write a LIKE test with the two wildcards to find text that starts, ends or contains something.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The two wildcards

WildcardStands forPatternMatches
`%`Any number of characters, even none`'C%'`Any name that starts with C
`%`Any number of characters, even none`'%e'`Any name that ends with e
`%`Any number of characters, even none`'%ee%'`Any name with ee inside
`_`Exactly one character`'_ola'`Cola, and any other four-letter name ending ola

The cells students fill in are left blank in this preview.

Try it: three patterns

Code: sql
SELECT name FROM products WHERE name LIKE 'C%';

SELECT name FROM products WHERE name LIKE '%ee%';

SELECT name FROM products WHERE name LIKE '_o%';

-- Try 'A%' and then '%s'.

Capital letters and NOT LIKE

In SQLite, LIKE ignores capital letters for English letters, so 'c%' and 'C%' match the same names. Other database products can be strict about case, so check.

Put NOT in front to find the names that do not match: name NOT LIKE 'C%'.

Try it: the underscore on dates

Code: sql
-- Dates saved as text can be matched too.
SELECT sale_id, sale_day FROM sales WHERE sale_day LIKE '2026-09-1_';

SELECT sale_id, sale_day FROM sales WHERE sale_day LIKE '2026-09-0%';

Check

Have a go

Check

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.