TetSharing
SQL tutorial · 14 chapters
  1. Get started
  2. SELECT columns
  3. WHERE filters
  4. AND, OR, NOT, IN, BETWEEN
  5. ORDER BY and LIMIT
  6. LIKE patterns
  7. NULL values
  8. COUNT, SUM, AVG, MIN, MAX
  9. GROUP BY and HAVING
  10. INNER JOIN
  11. LEFT JOIN
  12. Subqueries
  13. INSERT, UPDATE, DELETE
  14. CREATE TABLE and constraints

Final SQL quiz
Cheat sheet: sql cheat sheet

Chapter 6 of 14 · By Ethan Cole · Updated November 21, 2026

SQL LIKE Operator: % and _ Wildcards for Text Search

= finds exact matches. LIKE finds text that fits a pattern: titles starting with "The", email addresses at a certain domain, product codes with a known prefix.

The two wildcards

  • % matches any sequence of characters, including none. 'The %' means "starts with The and a space"; '%data%' means "contains data anywhere".
  • _ matches exactly one character. '_a%' means "the second character is a", which is why Maya and Daniel match but Rosa does not.

Every other character in the pattern must match itself.

SQLite · editable

Expected output

title
The Quiet Harbor
The Last Lantern
title
Small Data, Big Ideas
name
Maya Lindqvist
Daniel Okafor

Case sensitivity differs by database

In SQLite, LIKE ignores case for the 26 ASCII letters by default, so '%data%' finds "Small Data, Big Ideas". PostgreSQL's LIKE is case-sensitive and offers ILIKE for case-insensitive matching; MySQL's behavior depends on the column's collation. When portability matters, compare lower(title) LIKE '%data%', which works everywhere.

For case-sensitive patterns in SQLite, use GLOB, which uses Unix-style wildcards: * for any sequence and ? for one character, as in title GLOB '*Data*'.

Matching a literal % or _

To search for an actual percent sign or underscore, choose an escape character with ESCAPE: WHERE code LIKE '10\%%' ESCAPE '\' finds values that start with "10%".

Performance

A pattern that starts with a fixed prefix, like 'The %', can sometimes use an index. A pattern that starts with % cannot: the database must check every row. That is fine for small tables like ours. For searching words in large amounts of text, databases provide full-text search instead; SQLite's is called FTS5.

NOT LIKE

NOT LIKE keeps rows that do not match. Remember that rows where the column is NULL match neither LIKE nor NOT LIKE.

Common mistakes

  • Forgetting the wildcards: title LIKE 'Data' behaves like = and matches only the exact title "Data".
  • Using * with LIKE, or % with GLOB.
  • Assuming case-insensitive matching works the same way in every database.

Summary

  • % matches any run of characters; _ matches exactly one.
  • SQLite's LIKE is case-insensitive for ASCII letters; GLOB is case-sensitive.
  • Leading % patterns scan the whole table; use full-text search for big text.

Quiz: LIKE patterns

1. Which pattern finds titles ending in "Code"?

A leading % allows anything before "Code" and nothing after it.

2. What does _ match in a LIKE pattern?

_ is the single-character wildcard.

3. In SQLite, does 'ABC' LIKE 'abc' match?

SQLite's LIKE is case-insensitive for ASCII letters unless configured otherwise.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.