Quick Reference
The LIKE keyword is used in a WHERE clause to search for a specified pattern in a column. It can use two wildcards: % and _.
- % – represents zero, one, or multiple characters
- _ – represents a single character
The following selects all customers from the Customers table with a last_name starting with “y”.
SELECT * FROM Customers
WHERE last_name LIKE 'y%';
The following selects all customers from the Customers table with a last_name ending with “y”.
SELECT * FROM Customers
WHERE last_name LIKE '%y';
The following selects all customers from the Customers table with a last_name that has “ea” in any position.
SELECT * FROM Customers
WHERE last_name LIKE '%ea%';
The following selects all customers from the Customers table with a last_name that starts with “a” and are at least 7 characters in length.
SELECT * FROM Customers
WHERE last_name LIKE 'a______%';
SQL Notes:
- Any work being done to modify the structure of a database or delete tables or the the database itself should only be done after making a recent backup
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.