Geek Slack

My SQL Tutorial
About Lesson


MySQL Wildcards


MySQL Wildcards

Wildcards in MySQL are special characters used in conjunction with the LIKE operator to perform pattern-matching searches in strings.

1. % Wildcard

The % wildcard represents zero or more characters.

Example:

SELECT * FROM products WHERE name LIKE 'App%';

This query will retrieve all products whose name starts with “App”.

2. _ Wildcard

The _ wildcard represents a single character.

Example:

SELECT * FROM customers WHERE phone LIKE '12345_';

This query will retrieve customers whose phone number starts with “12345” followed by one character.

3. [character_list] Wildcard

The [character_list] wildcard matches any single character within the specified list or range.

Example:

SELECT * FROM products WHERE name LIKE '[BM]acbook';

This query will retrieve products whose name starts with either “B” or “M” followed by “acbook” (e.g., “Backbook” or “Macbook”).

Using wildcards in MySQL allows for flexible and powerful pattern-matching searches in database queries.

Join the conversation