Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Modifying Data with SQL Deleting Data From a Database Review and Practice

Sin Ieng Mou
Sin Ieng Mou
822 Points

Can I use the keyword IN for a group of wild card texts?

In this SQL playground, the third practice question asks us to remove actors with the first name of "Yuri" , "Walter" and "Victor".

I know the following query can do the work, where it will delete all rows with the three first names stated in the question: DELETE FROM actors WHERE name LIKE "Yuri%" OR name LIKE "Walter%" OR name LIKE "Victor%";

but at the same time I'm thinking whether or not we could save up some time and use the keyword IN for these wildcard first names....like: DELETE FROM actors WHERE name IN ("Yuri%", "Walter%", "Victor%");

Thanks for helping!

6 Answers

but at the same time I'm thinking whether or not we could save up some time and use the keyword IN for these wildcard first names....like: DELETE FROM actors WHERE name IN ("Yuri%", "Walter%", "Victor%");

Hi Sin,

The simple answer is no, you can't use the LIKE and IN operators together.

In your example of a potential shortened query, you omit the LIKE operator, which you need to search for patterns and use wildcards like "%." The query below will not work.

DELETE FROM actors
WHERE name LIKE IN ("Yuri%", "Walter%", "Victor%");

Unfortunately, you will have to write out each LIKE statement. The query below is correct and will work.

DELETE FROM actors
WHERE name LIKE "Yuri%"
OR name LIKE "Walter%"
OR name LIKE "Victor%";

For more information, check out this stackoverflow thread.

I did:

delete from actors where name like "Yuri %" or name like "Walter %" or name like "Victor %";

To ensure the whole first name was checked.

hi, but what happens to 12992 Yuriko Ishida? when we use "Yuri%". it will be deleted too! there are two different names! :)

In case anyone is looking for the same answer that I have been looking for regarding how to leave out the entries like "Yuriko" - you need to leave a space between the text and the % wildcard.

Instead of "Yuri%" it needs to be "Yuri %". You can do the same with Victor to leave out any Victorias.

Olive Ledge
Olive Ledge
1,769 Points

omg, genius! thank you!!

I tried this, Sin Ieng Mou, as you probably also did. It didn't work for me.

DELETE FROM actors WHERE name IN ("Yuri%", "Walter%", "Victor%");

Of course, this actors table is too darn long. It's very slow to load and check results to see whether the command worked. :(

Yes, you can do that.