The SQL WHERE LIKE syntax
The general syntax is:
SELECT column-names
FROM table-name
WHERE column-name LIKE value
Optional
Wildcard characters allowed in 'value' are % (percent) and _ (underscore).
A % matches any string with zero or more characters.
An _ matches any single character.
PRODUCT |
Id |
ProductName |
SupplierId |
UnitPrice |
Package |
IsDiscontinued |
SQL WHERE LIKE Examples
Problem: List all products with names that start with 'Ca'
SELECT Id, ProductName, UnitPrice, Package
FROM Product
WHERE ProductName LIKE 'Ca%'
Results: 2 records.
Id |
ProductName |
UnitPrice |
Package |
18 |
Carnarvon Tigers |
62.50 |
16 kg pkg. |
60 |
Camembert Pierrot |
34.00 |
15-300 g rounds |
PRODUCT |
Id |
ProductName |
SupplierId |
UnitPrice |
Package |
IsDiscontinued |
Problem: List all products that start with 'Cha' or 'Chan' and have one more character.
SELECT Id, ProductName, UnitPrice, Package
FROM Product
WHERE ProductName LIKE 'Cha_' OR ProductName LIKE 'Chan_'
Results: 2 records.
Id |
ProductName |
UnitPrice |
Package |
1 |
Chai |
18.00 |
10 boxes x 20 bags |
2 |
Chang |
19.00 |
24 - 12 oz bottles |