SQL Beginner Challenge 15: Pattern Matching with LIKE

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_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price

Sample Data

product_idnamecategoryprice
101Wireless MouseAccessories24.99
102Mechanical KeyboardAccessories89.00
103USB-C HubAccessories34.50
104USB Flash DriveAccessories19.99
105Laptop StandWorkspace39.99
106WebcamAccessories59.99

Your Task

Write a SQL query that returns:

  • name
  • price

…but only for products whose name contains the text USB.

Expected Output

nameprice
USB-C Hub34.50
USB Flash Drive19.99

Constraints

  • Use the LIKE operator
  • 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 contains USB anywhere.
  • % 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

  1. Forgetting wildcards
    WHERE name LIKE 'USB' -- ❌ exact match only
  2. Assuming case sensitivity
    • Behavior depends on the database (some are case-sensitive, some aren’t).
  3. Using = instead of LIKE for partial matches

Optional Extension (Mini Bonus)

Try:

  1. Find products whose names start with USB
  2. Find products whose names end with Drive
  3. Combine LIKE with AND or OR

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.