Stockertim Dictionary · Technology
LIKE pattern
Also called LIKE operator, SQL LIKE, LIKE wildcard search
In short
A text pattern used with SQL's LIKE operator to match values of a given shape, where the % sign stands for any run of characters and _ for exactly one.
- Beginner
- Concept
- Checked
In detail
LIKE lets a WHERE clause match text by shape rather than by exact value. The pattern is written in single quotes and may contain two wildcards: % matches any sequence of characters, including none, and _ matches exactly one character. WHERE surname LIKE 'Mc%' keeps every surname starting with Mc; WHERE code LIKE 'A_7' keeps three-character codes that start with A and end with 7.
The position of the wildcard decides the match. 'Mc%' means starts with, '%son' means ends with and '%bank%' means contains anywhere. A pattern with no wildcard behaves like an exact comparison. NOT LIKE reverses the test, and a pattern can be combined with other conditions using AND and OR in the usual way.
Whether LIKE is case-sensitive depends on the database product and its settings, so 'lagos%' may or may not match Lagos. Where it matters, both sides can be converted first with LOWER() or UPPER(). To search for a literal % or underscore, the pattern needs an escape character declared with ESCAPE, otherwise the symbol acts as a wildcard.
Patterns that begin with % force the database to read every value, because it cannot use an index to jump to a starting letter, so they are slow on very large tables. LIKE also matches more than intended surprisingly often: '%oil%' catches Boiler Parts as well as Oil Traders. For complex shapes many databases offer regular expressions as a separate feature.
Worked example
A wholesaler in Mombasa has 800 customer names and wants every customer whose name contains the word Hardware.
- Write:
SELECT name FROM customers WHERE LOWER(name) LIKE '%hardware%'; - Lowering the case first means Hardware, HARDWARE and hardware all match.
- The query returns 32 names; 32 / 800 = 4% of customers.
The list is checked by eye, and two unrelated names that merely contain the letters are removed before use.
In practice
Analysts use LIKE to find records by prefix (all accounts starting 40), by keyword in a description field, or to catch spelling variants during data cleaning. In spreadsheets the same idea appears as wildcard criteria in COUNTIF and SUMIF, where * plays the role of %.
Watch out
- Spreadsheet wildcards use
*and?, SQL uses%and_; copying a pattern between the two quietly matches nothing. - A leading
%prevents index use and can make a query very slow on a large table.
Learn it properly
Official sources
- The Government Data Quality Framework · UK Government Data Quality Hub
Facts last checked on 9 November 2026.
Education, not advice: the Stockertim Dictionary explains what terms mean. It never recommends buying or selling anything.