mysqldude

SELECT LIKE %

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
LIKE '%%%' matches every row (original)
original post
✓✓✓✓✓✓✓✓✓
LIKE '%\%%' matches only values containing % (original)
original post
✓✓✓✓✓✓✓✓✓
RLIKE '%' (original)
original post
✓✓✓✓✓✓✓✓✓
LIKE '%!%%' ESCAPE '!' (works with NO_BACKSLASH_ESCAPES too)
modern rewrite
✓✓✓✓✓✓✓✓✓
LOCATE('%', v) > 0 (no pattern at all)
modern rewrite
✓✓✓✓✓✓✓✓✓
LIKE '%%%' matches every row (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
LIKE '%\%%' matches only values containing % (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
RLIKE '%' (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
LIKE '%!%%' ESCAPE '!' (works with NO_BACKSLASH_ESCAPES too) modern rewrite
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
LOCATE('%', v) > 0 (no pattern at all) modern rewrite
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

The original article

First published 2012-03-05. The text below is the original; the table above shows how it behaves on current versions.

This may sound easy to perform but as the percent ’%’ is used as a wildcard in SQL this becomes a little trickier. Imagine we have a table that is full of numbers but some have been added incorrectly and include the percent symbol. We need to identify these ones.

The following SQL query will return all rows

SELECT * from table WHERE field LIKE '%%%';

What we need to do is to escape character (prepending a ) the percentage to indicate that it is not the wildcard but the actual character we are searching for.

SELECT * from table WHERE field LIKE '%\%%';

This will return the correct set of rows containing the % character.

Another way of performing this is using the regular expression search (RLIKE which is a synonym for regexp) as follows:

SELECT * from table WHERE field RLIKE '%';