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.

Previous: Lists and ranges: IN and BETWEEN · Next: Labels with CASE · All lessons