BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Search text with a pattern

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. Matches text that follows a pattern, not exact text.
    SELECT * FROM products WHERE product_name LIKE 'NovaSport%'
  2. % means "any letters here", so this means "starts with NovaSport".
    SELECT * FROM products WHERE product_name LIKE 'NovaSport%'
  3. % first means "ends with". % on both sides means "contains".
    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, 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 →
About 5–10 minutes · no sign-up needed