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 triallfkwtz
12,295 PointsWhat's the best query to run for "Remove Actors"?
I first tried to use IN alongside LIKE, but that apparently doesn't work, so I used:
DELETE FROM actors WHERE name LIKE "Yuri %" OR name LIKE "Walter %" OR name LIKE "Victor %";
Aaron Campbell
16,267 PointsI am glad you at least added the space before each % sign.
Chufan Xiao
18,955 PointsI think this is the most straightforward solution
8 Answers
Mark VonGyer
21,239 PointsHere's a tip for good practice.
Before running the DELETE script, use a SELECT script first
SELECT * FROM...
and see what is returned. If it is what you want to delete then go ahead!
Jonathan Grieve
Treehouse Moderator 91,253 PointsI'm willing to bet your query worked.
The query didn't return any results but it wasn't meant to. I did a query myself and then looked for Yuri and there was no record of him. Run the query again and then look at the data in the playground. :-)
DELETE FROM actors WHERE name LIKE "Yuri%" OR name LIKE "Walter%" OR name LIKE "Victor%";
lfkwtz
12,295 PointsI know it worked, I was just wondering if there was a better way to do it.
Jonathan Grieve
Treehouse Moderator 91,253 PointsNot that i know of. :-)
Petrov von Petrov
21,916 PointsI was also looking for a better solution than repeating "name LIKE" 3 times, and, after seeing, as you did, that the LIKE IN combination didn't work, found the REGEXP expression. It would go like this:
DELETE FROM actors WHERE name REGEXP '^Yuri|^Walter|^Victor';
This, however, won't work, because the SQL playground won't recognize REGEXP as a valid function. I haven't tried it in a real MySQL database, so I can't be sure that it would work, but supposedly it would.
BTW, ended up using a statement like yours. It's repeating, but works.
Kirill Kuptsov
732 PointsDELETE FROM actors WHERE name LIKE "Yuri %" OR name LIKE "Walter %" OR name LIKE "Victor %";
Andrew Winkler
37,739 PointsHi, there is a better way:
DELETE FROM actors WHERE name IN ('Yuri', 'Walter', 'Victor');
Note that your original code had spaces, likely that's why it didn't work the first time. If there aren't spaces in the data set, that would likely throw and error.
lfkwtz
12,295 PointsIt worked fine and the spaces were intentional due to names such as Victoria and Yuriko. Your solution doesn't seem to work.
sradms0
Treehouse Project ReviewerI think this would only account for the field holding the exact name. You need to use regex characters.
Carl Peters III
701 PointsEasiest way I came up that works with was:
DELETE FROM actors WHERE name LIKE "Yuri%" OR "Walter%" OR "Victor%";
Ilya Zaberezhnyy
5,024 PointsHi! Here is my way:
DELETE FROM actors WHERE name LIKE "Yuri%" AND "Walter%" AND "Victor%";
Kam Soon Cheng
1,275 PointsHi everyone, here my way:
DELETE FROM actors WHERE name = "Yuri%" OR "Walter%" OR "Victor%";
Chufan Xiao
18,955 Pointsuse like plz
Christian Higgins
15,758 PointsDid it work?
Cristian Glodeanu
4,031 PointsCristian Glodeanu
4,031 PointsThe query in the original question is the right query, the one that has a single <space> before each
"%"
! To prove that, run the asker's DELETE statement, then run another SELECT without that <space>:SELECT * FROM actors WHERE name LIKE "Yuri%" OR name LIKE "Walter%" OR name LIKE "Victor%";
You will see that it returns this:
This means that, without that extra <space>, the wrong actors would have been deleted as well. So take care! :)