skip to today's puzzle

LIKE matches text against a pattern

Starting table: menu_items

Starting menu_items data before the example query
name
Mint mocha
Latte
Iced mocha
Scone

LIKE compares a column to a pattern instead of an exact string. The percent sign is a wildcard: it stands for any run of characters. So 'garden%' means starts with garden, and '%garden%' means contains garden anywhere. Every other character in the pattern still has to appear exactly as written.

A tiny example

In plain English: Show me the menu items with the word mocha somewhere in their name.

SELECT name
FROM menu_items
WHERE name LIKE '%mocha%';

Query result

name
Mint mocha
Iced mocha

These are the only menu item names with the word mocha somewhere inside them.

Common questions

What do % and _ mean in a LIKE pattern?
% stands for any run of characters, including none at all, and _ stands for exactly one character. So 'a%' matches anything starting with a, and '_at' matches cat, bat and hat.
Is LIKE case-sensitive?
It depends on the database. PostgreSQL is case-sensitive (use ILIKE for a case-insensitive match), while MySQL and SQL Server usually ignore case. SQLite ignores case for plain English letters.

Related SQL lessons

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle