Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: LIKE, wildcard matching, text filtering
Goal: Find rows based on partial text matches.
The Scenario
A product manager asks:
“Can we find all products whose names contain the word ‘USB’?”
Exact matches won’t work here.
You need a way to filter text by pattern, not by the full value.
That’s what LIKE is for.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
Sample Data
| product_id | name | category | price |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 |
| 102 | Mechanical Keyboard | Accessories | 89.00 |
| 103 | USB-C Hub | Accessories | 34.50 |
| 104 | USB Flash Drive | Accessories | 19.99 |
| 105 | Laptop Stand | Workspace | 39.99 |
| 106 | Webcam | Accessories | 59.99 |
Your Task
Write a SQL query that returns:
nameprice
…but only for products whose name contains the text USB.
Expected Output
| name | price |
|---|---|
| USB-C Hub | 34.50 |
| USB Flash Drive | 19.99 |
Constraints
- Use the
LIKEoperator - Use wildcard characters (
%) - Do not use
SELECT *
Hint (Optional)
The % symbol matches any number of characters.
Examples:
%USB%→ contains “USB”USB%→ starts with “USB”%USB→ ends with “USB”
SELECT
name,
price
FROM products
WHERE name LIKE '%USB%';
Explanation
LIKE '%USB%'matches any product name that containsUSBanywhere.%before and after the text allows characters on both sides.- This is commonly used for:
- Search features
- Filtering names or descriptions
- Data exploration
Common Mistakes
- Forgetting wildcards
WHERE name LIKE 'USB' -- ❌ exact match only - Assuming case sensitivity
- Behavior depends on the database (some are case-sensitive, some aren’t).
- Using
=instead ofLIKEfor partial matches
Optional Extension (Mini Bonus)
Try:
- Find products whose names start with
USB - Find products whose names end with
Drive - Combine
LIKEwithANDorOR
Next Challenge
Beginner Challenge #16: Match Single Characters with _ (underscore wildcard)
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.