Hi, I'm a MySQL noob and I want to delete some records in a specific table that contains specific words. For example, if this record has the words strawberry, apple and banana, I want to select it all and delete it all. How can I do it? I tried this: DELETE * FROM [table name] WHERE [field name] = "strawberry, apple, banana"; Code (markup): But it was wrong...
DELETE * FROM [table name] WHERE [field name] like "%strawberry%" or [field name] like "%apple%", or [field name] like "%banana%"; It may be very slow, but will work. You can try to use regexp also.
Take care here! this query would also delete rows containing pineapples! You might not want this. Add a space to cover this. So the syntax should be like this... DELETE FROM [table name] WHERE ( [field name] like '% strawberry%' or [field name] like '% apple%' or [field name] like '% banana%') Backup first before running "like" deletes
Does the field name contain other text as well, or just 1 word? If it is just 1 word, you would want to do it a little different. LIKE queries take a lot more resources than a standard column = value. If you have multiple values, you can use: DELETE FROM [table name] WHERE [field name] IN ('strawberry', 'apple', 'banana');