Interview Q&A / SQL & DBMS

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do the LIKE wildcards % and _ work in SQL?

SHORT ANSWER

In LIKE, % matches any number of characters including none, and _ matches exactly one character. Use NOT LIKE to exclude, and ESCAPE to search for a literal % or _.

Explain it simply

Think of a search box where % means "anything can go here" and _ means "exactly one letter goes here". It is like filling a crossword: _ is one empty square, % is a stretch of any length.

Example

sql
SELECT name FROM students WHERE name LIKE 'A%';      -- starts with A
SELECT name FROM students WHERE name LIKE '%an';     -- ends with an
SELECT name FROM students WHERE name LIKE '%ar%';    -- contains ar
SELECT name FROM students WHERE name LIKE '_a%';     -- second letter is a
SELECT name FROM students WHERE name LIKE '____';    -- exactly 4 letters

To search for a real percent sign, escape it:

sql
SELECT * FROM offers WHERE label LIKE '50\%%' ESCAPE '\';

This matches labels beginning with 50%.

Case sensitivity depends on the database and collation. MySQL and SQL Server are usually case-insensitive by default; PostgreSQL LIKE is case-sensitive, and ILIKE is the case-insensitive version.

What to say in the interview

"% matches zero or more characters, _ matches exactly one. A pattern that starts with % like '%an' cannot use a normal index, so on big tables it forces a scan."

Common mistakes

  • Writing LIKE 'A*' with the shell-style star.
  • Forgetting that LIKE 'abc' with no wildcard is just an equality check.

#sql#like#pattern-matching

Related questions

Practise more SQL & DBMS questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open SQL & DBMS quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.