LIKE SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

LIKE matches too much: _ and % are wildcards (escape them)

Searching for text containing _ or % returns unexpected rows because LIKE treats them as wildcards.

Exact message you may see LIKE underscore matches any characterLIKE with percent sign matches too many rowsescape underscore in LIKELIKE ESCAPE clauseLIKE wildcard injection
Seen on: SQL MySQL PostgreSQL

Meaning

In LIKE, % matches any string and _ matches any single character. Escape literal characters with an ESCAPE clause (LIKE '50\%%' ESCAPE '\'), and always escape user input to avoid unintended matches (and injection-style surprises).

Common causes

  • Searching for file names with underscores
  • User input containing % or _
  • No ESCAPE character defined
  • Leading wildcard preventing index use
  • Case-sensitivity differences between databases

⚡ Quick fix

  1. Escape wildcards: LIKE 'a\_b%' ESCAPE '\'
  2. Escape user-provided search terms
  3. Use full-text search for large text

Detailed fix by platform

SQL

  1. SELECT * FROM files WHERE name LIKE 'report\_2026%' ESCAPE '\';

How to diagnose

  1. Input — Has _ or %?
  2. ESCAPE — Used?
  3. Index — Usable?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

22P02 — ERROR: invalid input syntax for type integer: "abc" (PostgreSQL)22P02cartesian — Query returns far too many rows: accidental Cartesian product (missing JOIN condition) (SQL)cartesianCASE — CASE expression returns mixed types: conversion failed / types cannot be matched (SQL)CASECOUNT — COUNT(column) ignores NULLs: counts differ from COUNT(*) (SQL)COUNTdate format — Dates mixed up: dd/mm/yyyy vs mm/dd/yyyy, ISO 8601 recommended (SQL)date formatimplicit conversion — Query slow because of an implicit type conversion or function on the column (index not used) (SQL)implicit conversionIN list — Too many values in an IN list / too many parameters (limit exceeded) (SQL)IN listLIKE

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.