The LIKE
operator is used in a WHERE
clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE
operator:
%
represents zero, one, or multiple characters_
represents one, single characterSELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern
Select all customers that starts with the letter "a":
SELECT * FROM Customers
WHERE CustomerName LIKE '**a%'**
Select all customers from a city that contains the letter ‘L’:
SELECT * FROM Customers
WHERE city LIKE **'%L%'**;
To return records that ends with a specific letter or phrase, add the %
at the beginning of the letter or phrase.
SELECT CustomerName FROM Customers
WHERE CustomerName LIKE **'%a'**;
The _
wildcard represents a single character.
It can be any character or number, but each _
represents one, and only one, character.
SELECT * FROM Customers
WHERE city LIKE `L_nd__`