Text patterns with LIKE
Stage 2: Filtering · Lesson 8 of 17 · 4 min read · free, interactive
LIKE matches text against a pattern. % stands for any run of characters (even none), _ for exactly one character.
SELECT name FROM players WHERE name LIKE 'M%';
Names starting with M.
SELECT name FROM items WHERE name LIKE '%Potion';
Names ending with Potion.
SELECT name FROM players WHERE name LIKE '_e%';
Second letter is e.
LIKE is case-sensitive. PostgreSQL also has ILIKE, which ignores case:
SELECT name FROM players WHERE name ILIKE '%a%';
Practice
Each answer runs in your browser and is checked on hidden data.
- Write the query: Return the
nameof every item whose name ends withPotion. Row order does not matter. - Fill in the blanks: Return the
nameof players whose name contains the letter a, in upper or lower case. Row order does not matter. - Find the bug: Return the
nameof players whose name starts withR. Row order does not matter.
Previous: Lists and ranges: IN and BETWEEN · Next: Labels with CASE · All lessons