LIKE & Pattern Matching in SQL

From the SQL cheat sheet ยท SELECT & Filtering ยท verified Jul 2026

LIKE & Pattern Matching

Filter text with wildcard patterns.

sql
-- % matches any number of characters
SELECT * FROM users WHERE name LIKE 'J%';       -- Starts with J
SELECT * FROM users WHERE email LIKE '%@gmail%'; -- Contains @gmail

-- _ matches exactly one character
SELECT * FROM users WHERE name LIKE '_ohn';      -- ?ohn

-- NOT LIKE
SELECT * FROM users WHERE name NOT LIKE '%test%';
๐Ÿ’ก % matches any number of characters (including zero); _ matches exactly one
โšก PostgreSQL uses ILIKE for case-insensitive matching; MySQL LIKE is case-insensitive by default
๐Ÿ“Œ LIKE '%term%' cannot use indexes efficiently โ€” consider full-text search for large tables
๐ŸŸข Use ESCAPE to match literal % or _ characters in your pattern
likewildcardspattern-matching

More SQL tasks

Back to the full SQL cheat sheet