- The LIKE keyword works with wildcards
- LIKE is used with text fields (strings)
- Use the LIKE operator to specify search patterns in conditions
SELECT <column1>,
<column2>
FROM <table>
WHERE <column1> LIKE 'text%';
- The % wildcard matches any sequence of characters
- Every value found in column1 that starts with text will match
- A value also matches if nothing follows text in the string
- Case sensitivity depends on the DBMS and its configuration
- A pattern may contain more than one wildcard
SELECT <column1>,
<column2>
FROM <table>
WHERE <column1> LIKE '%text in the middle%';
- The % wildcard matches any sequence of characters, but NULL is unknown and is not a string
Select the product ID and name from Products where 'bean bag' occurs anywhere in the product name
SELECT prod_id,
prod_name
FROM Products
WHERE prod_name LIKE '%bean bag%';
| prod_id | prod_name |
| BNBG01 | Fish bean bag toy |
| BNBG02 | Bird bean bag toy |
| BNBG03 | Rabbit bean bag toy |