SQL % Operator in Strings: LIKE Wildcards Explained

How-to basics · Updated November 23, 2026

The % operator in SQL is not a standalone operator—it is the wildcard character used with the LIKE operator to match any sequence of zero or more characters in a string. For example, WHERE name LIKE 'A%' finds all names starting with ‘A’. This article explains how % works, how to use it correctly, and common pitfalls.

What Exactly Is the % Operator?

In SQL, % is a wildcard that represents zero, one, or many characters. It is only meaningful when paired with LIKE (or ILIKE in PostgreSQL for case-insensitive matching). Without LIKE, % is just a modulo operator in arithmetic (e.g., SELECT 10 % 3 returns 1). In string contexts, % is used to search for patterns. For instance:

  • WHERE title LIKE '%SQL%' matches any title containing ‘SQL’ anywhere.
  • WHERE title LIKE 'SQL%' matches titles starting with ‘SQL’.
  • WHERE title LIKE '%SQL' matches titles ending with ‘SQL’.

The underscore _ is the other wildcard, matching exactly one character. So LIKE 'A_C' matches ‘ABC’ but not ‘AC’ or ‘ABBC’.

How the % Wildcard Works with LIKE

When you use LIKE, the database scans the string column and compares each value against the pattern. The % matches any sequence of characters, including an empty sequence. This makes it powerful for fuzzy searches. For example, in a customer table, you can find all emails from a domain:

SELECT * FROM customers WHERE email LIKE '%@gmail.com';

This returns rows where the email ends with ‘@gmail.com’. The leading % means ‘any characters before’. You can also combine wildcards: LIKE '%a%b%' matches any string containing an ‘a’ followed later by a ‘b’. Note that LIKE is case-sensitive in many databases (e.g., PostgreSQL with default collation, SQL Server with default collation), but case-insensitive in MySQL by default. To force case-insensitivity in PostgreSQL, use ILIKE or LOWER(column) LIKE LOWER(pattern).

Using % in Different SQL Databases

The % wildcard works across all major SQL databases—MySQL, PostgreSQL, SQL Server, SQLite, Oracle—with slight syntax differences. In SQL Server, you can also use % with LIKE in the same way. Oracle requires LIKE and treats % identically. SQLite also supports LIKE with %. In all cases, the pattern is a string literal, and you can escape % if you need to match a literal percent sign. For example, to find strings containing ‘50%’, use LIKE '%50\%%' ESCAPE '\' (the backslash is the escape character). In MySQL, the default escape is backslash, so you can write LIKE '%50\%%' without specifying ESCAPE. In SQL Server, use LIKE '%50[%]%' with brackets to escape.

Common Problems and Misconceptions

One common mistake is using % without LIKE, like WHERE name = '%John%'—this will not match anything because it looks for the literal string ‘%John%’. Another issue is performance: leading wildcards (e.g., '%John') prevent the database from using an index, causing full table scans. If you have a large table, consider using full-text search or a reverse index. Also, remember that LIKE with % does not match NULL values—you need IS NULL separately. A frequent misconception is that % matches any number of characters including newlines, which it does, but in some databases, newline handling depends on collation. Finally, be careful with user input: always parameterize queries to avoid SQL injection; never concatenate user input directly into a LIKE pattern without escaping.

How to Choose Between LIKE, =, and Full-Text Search

Use = for exact matches, LIKE for simple pattern matching, and full-text search for complex text queries. For example, if you need to find a product by exact SKU, use WHERE sku = 'ABC123'. If you need to find products with ‘blue’ in the name, use LIKE '%blue%'. But if you need to search for multiple words with ranking, stemming, or fuzzy matching, use full-text search (e.g., MySQL’s MATCH ... AGAINST, PostgreSQL’s tsvector). Full-text is faster for large texts and supports language-aware search. For simple prefix searches (e.g., ‘John%’), a regular index can help if you use LIKE 'John%' (without leading wildcard).

Performance and Indexing with %

When you use LIKE 'abc%' (no leading wildcard), the database can use a B-tree index on that column. However, LIKE '%abc%' cannot use a standard index because the wildcard is at the start. To speed up such searches, you can create a reverse index (store the reversed string) or use a trigram index in PostgreSQL (with the pg_trgm extension). In MySQL, you can use FULLTEXT indexes for better performance on large text columns. For small tables, the performance difference is negligible, but for millions of rows, a leading wildcard can be very slow. Always test with EXPLAIN to see if the query uses an index.

Alternatives to LIKE with %

If you need more advanced pattern matching, consider:

  • Regular expressions: Use REGEXP_LIKE in Oracle, REGEXP in MySQL, ~ in PostgreSQL, or LIKE with regex in SQLite (via REGEXP). These offer more flexibility (e.g., WHERE name ~ '^J.*n$').
  • Full-text search: For natural language queries, use built-in full-text features.
  • SOUNDEX: For phonetic matching, use SOUNDEX in SQL Server or MySQL.
  • String functions: Use CHARINDEX (SQL Server), INSTR (Oracle/MySQL), or POSITION (PostgreSQL) to find a substring and then filter manually—though this is often less efficient than LIKE.

Each has trade-offs in syntax and performance. For most simple substring searches, LIKE '%...%' is sufficient and readable.

Frequently Asked Questions

Can I use % with the equals sign?

No, = performs an exact match. To use wildcards, you must use LIKE. For example, WHERE name = 'A%' looks for the literal ‘A%’, not names starting with A.

How do I search for a literal percent sign?

Use an escape character. In MySQL, you can write LIKE '%50\%%' (backslash escapes the first %). In SQL Server, use LIKE '%50[%]%'. In PostgreSQL, use LIKE '%50\%%' ESCAPE '\'.

Does % match newline characters?

Yes, % matches any character, including newlines, in most databases. However, in some collations, newline handling might differ, but generally it matches.

Is LIKE case-sensitive?

It depends on the database and collation. MySQL is case-insensitive by default, while PostgreSQL and SQL Server are case-sensitive by default. Use ILIKE in PostgreSQL or LOWER() to make it case-insensitive.

Can I use % in a JOIN condition?

Yes, you can use LIKE in a JOIN, e.g., ON a.name LIKE b.pattern. But be aware of performance implications—it may cause a full table scan.

Why does my query with % return unexpected results?

Check for NULL values (they are not matched by LIKE), check case sensitivity, and ensure you are not using = instead of LIKE. Also, verify that the column data type is a string (CHAR, VARCHAR, TEXT).

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.