Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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! :)

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. :(

Kate McPherson
Kate McPherson
2,149 Points

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.

Yes, you can do that.