Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to delete entries that contain part of string?

I have a MySQL table where I want to delete all the entries that contain a part of a string -

for example, in the field "photo_name", a lot of entries might have strings like these:

testb-image-0.jpg
testc-image-0.jpg
testd-image-0.jpg
etc ...

I want to delete all entries that have the term "image-0" as part of the string in this "photo_names" field -

How do you delete entries based on a part of a string?

like image 231
jScott Avatar asked Dec 17 '22 14:12

jScott


1 Answers

DELETE FROM mytable WHERE photo_name LIKE '%image-0.jpg'

Note that % stands for zero or more characters.
You can also use _ which stands for exactly 1 character.

like image 143
ibram Avatar answered Dec 19 '22 08:12

ibram