Geek Slack

My SQL Tutorial
About Lesson


MySQL LIKE Operator


MySQL LIKE Operator

The LIKE operator in MySQL is used in the WHERE clause to search for a specified pattern in a column. It can be used with wildcards to make the search more flexible.

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. Combined Wildcards

Wildcards can be combined for more complex searches.

Example:

SELECT * FROM products WHERE description LIKE '%red%shirt%';

This query will retrieve products with a description that contains the words “red” and “shirt”, in any order and separated by any characters.

The LIKE operator is powerful for searching for patterns in text data in MySQL databases.

Join the conversation