← ACARA Digital Technologies Years 9–10

Pattern matching with LIKE, % and _

LIKE matches text by pattern in a WHERE clause. % stands for any run of characters and _ for exactly one, so 'S%' finds values starting with S and '%son' finds values ending in son.

Understanding Pattern matching with LIKE, % and _ in ACARA Digital Technologies Years 9–10

What it does: The % at the start allows anything before 'son', so only values finishing with 'son' match. Each _ stands for exactly one character, so 'L__' matches an L followed by two more characters, such as Leo. The S comes first, then % allows any run of characters after it. '%S' would find names that END in S. = looks for the exact text L%, so it finds nothing. LIKE is needed for % to work as a wildcard. A % on both sides of 'at' lets any characters come before and after it, so 'at' can appear anywhere in the value.

Common mistakes: SQL LIKE uses % for any run of characters, not *. With 'S*' the * is just a star character, so no names match. It should be 'S%'. 'son%' finds names that START with son. To find names that END in son, put the % first: '%son'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 459–475) and word search (Modules 459–534).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which WHERE clause finds every student whose last name starts with S?
WHERE lastName LIKE 'S%'WHERE lastName LIKE '%S'
Matches
WHERE lastName LIKE 'S*'
↓
* is not a wildcard in SQL LIKE. Use % to match any run of characters, so the pattern should be 'S%'.
Applying
Meanings
Term
WHERE lastName LIKE 'S%'
Meaning
LIKE matches text by pattern in a WHERE clause. % stands for any run of characters and _ for exactly one, so 'S%' finds values starting with S and '%son' finds values ending in son.
Practice
SELECT firstName, lastName
Testing
Gaps
WHERE lastName 'S%';
Check Answer
Spots
2FROM students
3WHERE lastName LIKE 'S*';

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Tree Frog' badge — Leap of Logic, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which WHERE clause finds every student whose last name starts with S?
A. WHERE lastName LIKE 'S%' ✓
B. WHERE lastName LIKE '%S'
The S comes first, then % allows any run of characters after it. '%S' would find names that END in S.
2. Which pattern matches last names that end in son, like Jackson or Wilson?
A. LIKE '%son' ✓
B. LIKE 'son%'
% goes before son because anything can come before it. 'son%' finds values that start with son.
3. Which pattern finds product names that contain the letters at anywhere inside?
A. LIKE '%at'
B. LIKE '%at%' ✓
A % on both sides means any characters can come before and after at. '%at' only matches values that end in at.
4. In a LIKE pattern, what does the underscore _ stand for?
A. Exactly one character ✓
B. Any run of characters, even none
_ matches exactly one character. It is % that matches any run of characters, including none.
5. Which pattern matches Ava and Eva but not Elva?
A. LIKE '%va'
B. LIKE '_va' ✓
_ allows exactly one character before va. '%va' would also match Elva because % allows any number of characters.

Match the Pairs

WHERE lastName LIKE 'S%' → Finds students whose last name starts with S, followed by any number of other characters
WHERE name LIKE '%at%' → Finds names that contain the letters 'at' anywhere, such as Water Bottle or Calculator
Find last names that end in son by putting % before the ending → WHERE lastName LIKE '%son'
The _ wildcard matches exactly one character, so this finds three-letter first names starting with L → WHERE firstName LIKE 'L__'
WHERE lastName LIKE 'S*' → * is not a wildcard in SQL LIKE. Use % to match any run of characters, so the pattern should be 'S%'.
WHERE lastName = 'S%' → The = operator compares exact text, so the % is not a wildcard. Use LIKE to match a pattern.

Key Term

WHERE lastName LIKE 'S%'
LIKE matches text by pattern in a WHERE clause. % stands for any run of characters and _ for exactly one, so 'S%' finds values starting with S and '%son' finds values ending in son.

Fill in the Blanks

1. SELECT * FROM students WHERE lastName LIKE 'S%';
Hint: Type the keyword that compares a text field to a pattern.
2. SELECT firstName, lastName FROM students WHERE lastName LIKE 'S%';
Hint: Type the wildcard symbol that stands for any run of characters, so the value can end with anything after the S.
3. SELECT * FROM students WHERE lastName LIKE '%son';
Hint: Type the wildcard symbol that allows any characters before the fixed ending.
4. SELECT name FROM products WHERE name LIKE '%at%';
Hint: Type the wildcard symbol that lets anything follow the letters, so the pattern means contains.
5. SELECT * FROM students WHERE firstName LIKE 'Li_m';
Hint: Type the wildcard symbol that stands for exactly one character.

Spot the Error

Question 1
A SELECT firstName, lastName
B FROM students
C WHERE lastName LIKE 'S*';
Line C — SQL LIKE uses % for any run of characters, not *. With 'S*' the * is just a star character, so no names match. It should be 'S%'.
Question 2
A SELECT firstName, lastName
B FROM students
C WHERE yearLevel = 9
D AND lastName LIKE 'son%';
Line D — 'son%' finds names that START with son. To find names that END in son, put the % first: '%son'.
Question 3
A SELECT name FROM products
B WHERE name LIKE %at%
C ORDER BY name;
Line B — The LIKE pattern is text, so it must be wrapped in quotes. It should be WHERE name LIKE '%at%'.
Question 4
A SELECT firstName, lastName,
B FROM students
C WHERE firstName LIKE 'Z_e';
Line A — There is a comma after the last field in the SELECT list, but no more fields follow. Remove it: SELECT firstName, lastName.
Question 5
A SELECT firstName
B FROM students
C WHERE yearLevel = 8
D AND firstName = 'L___';
Line D — The = operator compares exact text, so the underscores are treated as real characters. Use LIKE so each _ stands for exactly one character.

Student with a class code? Join your class →