LIKE
Operator – Pattern Matching Made EasyThe LIKE
operator in MySQL is used to search for a specified pattern in a column. It is commonly used in the WHERE
clause to filter rows based on partial matches.
LIKE
%
– Matches zero or more characters_
– Matches exactly one characterLIKE
1. Find employees whose first name starts with 'J':
SELECT * FROM employees WHERE first_name LIKE 'J%';
Explanation: Finds names like 'John', 'Jane', 'Jack', etc.
2. Find employees whose last name ends with 'son':
SELECT * FROM employees WHERE last_name LIKE '%son';
Explanation: Matches 'Johnson', 'Wilson', 'Robson', etc.
3. Find employees whose email contains 'tech':
SELECT * FROM employees WHERE email LIKE '%tech%';
Explanation: Finds emails like 'info@techcorp.com', 'user@mytechnology.net', etc.
4. Find employees whose first name has 'a' as the second letter:
SELECT * FROM employees WHERE first_name LIKE '_a%';
Explanation: Matches names like 'Mark', 'David', 'Sally', etc. ('_' matches exactly one character before 'a')
Write a query to find employees whose department name contains 'Sale'.
SELECT * FROM employees WHERE department LIKE '%Sale%';
LIKE 'abc%'
matches values starting with 'abc'.LIKE '%abc'
matches values ending with 'abc'.LIKE '%abc%'
matches values containing 'abc' anywhere.LIKE '_a%'
matches values where the second character is 'a'._
for single-character wildcards and %
for multiple characters.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!