Lessons › SQL › Chapter 2: Filtering
SQL lesson
LIKE and wildcards
LIKE matches text that follows a pattern, not exact text. % stands for any letters. 'Nova%' means starts with Nova. '%Bottle' means ends with Bottle. '%Sport%' means it has Sport anywhere.
Try this lesson free →Example
Search text with a pattern
SELECT *
FROM products
WHERE product_name LIKE 'NovaSport%'| product_id | product_name | category | price |
|---|---|---|---|
| P1001 | NovaSport Running Shoes | Footwear | 89.99 |
| P1002 | NovaSport Yoga Mat | Fitness | 34.5 |
| P1005 | NovaSport Water Bottle | Fitness | 19.99 |
Step by step
- Matches text that follows a pattern, not exact text.
SELECT * FROM products WHERE product_name LIKE 'NovaSport%' - % means "any letters here", so this means "starts with NovaSport".
SELECT * FROM products WHERE product_name LIKE 'NovaSport%' - % first means "ends with". % on both sides means "contains".
SELECT * FROM products WHERE product_name LIKE 'NovaSport%'
Practice
1. Using customers, find the customers whose full_name starts with 'C'.
SELECT * FROM customers WHERE full_name LIKE 'C%'2. Using customers, find the customers whose email ends with '.com'.
SELECT * FROM customers WHERE email LIKE '%.com'3. Using products, find the products whose brand contains 'Home'.
SELECT * FROM products WHERE brand LIKE '%Home%'4. Using products, find the products whose category starts with 'E'.
SELECT * FROM products WHERE category LIKE 'E%'5. Using employees, show the full_name and role of employees whose role ends with 'Analyst'.
SELECT full_name, role FROM employees WHERE role LIKE '%Analyst'Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →