SQL Wildcards
All notes
SQL27 Nov 2026

Pattern matching with SQL wildcards

LIKE lets you filter text without an exact match. Two characters do almost all the work – here's exactly how.

wildcards.sql
SELECT name FROM customers
WHERE name LIKE 'A%';
Results
Aarav
Meera
Ananya
Rohan
Aditi
Kabir
Arjun
Priya

What's a wildcard?

A plain comparison is exact: name = 'Aarav' finds Aarav and nothing else – one letter off, and it comes back empty. A wildcard is a stand-in character you drop into a search pattern when you only know the shape of the text, not the exact string – "starts with A," "has an 'an' in it somewhere," "is exactly five letters."

LIKE is the SQL keyword that turns a plain string comparison into that kind of shape-matching search. It only understands a couple of special characters to describe that shape – everything else in the pattern still has to match literally.

Every wildcard, at a glance

%

Percent – any run of characters

Matches zero or more characters of any kind, including none at all.

'A%' → Aarav, Ananya
_

Underscore – exactly one

Matches exactly one character – never zero, never two.

'_abir' → Kabir
[ ]

Bracket list – not everywhere

Matches one character from a set. This is a SQL Server / MS Access extension – MySQL and PostgreSQL don't support it at all.

'[AR]%' → T-SQL only
\%

Escaping a literal

Need to match an actual % or _? Escape it and say so.

LIKE '50\%' ESCAPE '\'

The two you'll use constantly

Of the four above, % and _ are the ones that work the same in every major database. Here's exactly what each one does, with real examples.

% – any run of characters, including none

  • 'A%' – starts with A → Aarav, Ananya, Aditi, Arjun
  • '%a' – ends with a → Ananya, Priya
  • '%an%' – has "an" anywhere in the middle → Rohan, Simran

The part people forget: % can match zero characters too, so 'A%' would just as happily match the single letter "A" on its own as it matches "Aarav."

_ – exactly one character, never more or less

  • '_abir' – any first letter, then "abir" → Kabir
  • 'K_b_r' – K, any letter, b, any letter, r → Kabir

Each _ accounts for exactly one character position – line up five of them ('_____') and you've written "exactly five characters," full stop. Too short or too long, and it won't match no matter what the letters are.

Try it yourself

Type a pattern below – the names that match light up gold, computed live against the exact same rule MySQL and PostgreSQL use.

Try a pattern

Equivalent regular expression:

Aarav Meera Ananya Rohan Aditi Kabir Arjun Priya Simran Dhruv

Reading the pattern out loud

PatternReads asMatches here
'A%'starts with AAarav, Ananya, Aditi, Arjun
'%a'ends with aAnanya, Priya
'%an%'contains "an" anywhereRohan, Simran
'_abir'5 characters, ending "abir"Kabir
'K_b_r'5 characters, K_b_r with any 2nd and 4th letterKabir

Case sensitivity depends on the column's collation, not on LIKE itself – MySQL's default collations are case-insensitive, so 'a%' and 'A%' usually match the same rows.

The index gotcha

A trailing wildcard – 'A%' – can still use a standard B-tree index, because the engine can seek straight to rows starting with "A." A leading wildcard – '%an%' – can't: every row has to be scanned, since a match could start anywhere. On a large table, that's the difference between an index seek and a full scan.

Want to run these patterns against a real table?

Open the SQL compiler →