Skip to the content

LIKE

SQL · Unit 2: Filtering

Someone calls the store: I want that thing that starts with M, I can't remember what it's called. = is no help, because no product is named M.

LIKE compares against a pattern, and inside the pattern % stands for any text. 'M%' is an M and then anything. '%e' is anything and then an e at the end.

SELECT name
FROM products
WHERE name LIKE 'M%';

Returns

name
Mouse
Monitor

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Complete the code

    In the store's search box, someone has typed Hea and is waiting for suggestions. Fill in the blank with the pattern for what starts that way.

  2. 2. Predict the output

    Now the % goes in front. What does this query return?

  3. 3. Predict the output

    What does this query return?

  4. 4. Find the bug

    The search box should show everything with le in its name that costs 400 or less, which is two products. Only the Cable comes up. Which line has the problem?

  5. 5. Put the lines in order

    Someone types A in the category filter, and the search box shows the products of every category that starts that way. Put the query in order. Two lines don't belong.

  6. 6. Predict the output

    This pattern uses both wildcards. What does the query return?

  7. 7. Multiple choice

    The dates in orders look like this: 2026-01-09. Which condition returns only the orders from the first nine days of January, the 01 through the 09?

  8. 8. Predict the output

    Someone searches with caps lock on. What does this query return here?

  9. 9. Complete the code

    At the counter, someone looks up a customer by name, typing in lowercase and without accents, and wants to find Chloë. Fill in the blank with the pattern that does find her.

  10. 10. Put the lines in order

    Someone looks through the customers over 40 and types the letter e in the search box. Put the query in order. One line doesn't belong.

  11. 11. Write the code

    A package arrived with a torn label. All you can read is that the name ends in n and the city starts with Bo. Write a query that shows the name and the city, in that order, of whoever fits both clues.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →