We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Like

Sometimes we don't have the luxury of knowing exactly what it is we need to query. Have you ever wanted to look up a song or a video but you only remember part of the name? SQL offers us an option for when we're in situations LIKE this.

The LIKE keyword allows for the use of the % and _ wildcard operators. Let's focus on % first.

% Operator

The % operator will match zero or more characters. We can use this operator within our query string to find more than just exact matches, depending on where we place it.

Product Starts With “banana”

SELECT * FROM products
WHERE product_name LIKE 'banana%';

Product Ends With “banana”

SELECT * FROM products
WHERE product_name LIKE '%banana';

Product Contains “banana”

SELECT * FROM products
WHERE product_name LIKE '%banana%';

Assignment

Our HR team is dealing with a ticket from one of our users, but they're having trouble pulling up their record in the database. They are pretty sure the user's name starts with Bo.

Write a query that returns all fields for records in the users table where the user's name starts with Bo.

Tip

The LIKE operator expects a string value. Make sure the statement you are comparing against is wrapped in quotes, or SQL will think you're referring to a column!