BBampaa

Lessons › SQL › Chapter 2: Filtering

SQL lesson

LIKE and wildcards

LIKE finds rows where a text value matches a pattern rather than an exact phrase.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Searching Retail Product Names with LIKE and Wildcards

SELECT * FROM products
WHERE product_name LIKE 'NovaSport%'

Result:

product_idproduct_namecategoryprice
P1001NovaSport Running ShoesFootwear89.99
P1002NovaSport Yoga MatFitness34.5
P1005NovaSport Water BottleFitness19.99

Step by step

  1. The asterisk symbol means all columns.
    SELECT *
  2. FROM tells SQL which table to pull the data from.
    SELECT *
    FROM products
  3. WHERE keeps only the rows that match your condition.
    SELECT *
    FROM products
    WHERE product_name LIKE 'NovaSport%';

Practice

Try each one in your head first, then open the answer.

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, find the employees whose role ends with 'Analyst'.
SELECT * 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 →
About 5–10 minutes · no sign-up needed