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

**Code:** `LIKE` · **Category:** SQL · **Seen on:** SQL, MySQL, PostgreSQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/like-wildcard-underscore-percent-escape)
