Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL: delete all rows containing string "foo" in table "bar"

Tags:

mysql

What's the command to achieve this:
MYSQL: delete all rows containing string "foo" in table "bar"

like image 245
Captain Claptrap Avatar asked Nov 22 '10 18:11

Captain Claptrap


People also ask

What is the clause to delete all rows from the table?

The truncate command removes all rows of a table.

Can we delete a row with foreign key?

Here, ON DELETE CASCADE is added because when any row is deleted in one table the same gets deleted in the foreign referenced tables that are referencing the primary key in that table. Step-4: Verifying the database : To view the description of the tables in the database using the following SQL query as follows.


2 Answers

DELETE FROM bar where  field1 like '%foo%'  OR field2 like '%foo%' OR ... fieldLast like '%foo%' 
like image 136
Byron Whitlock Avatar answered Sep 20 '22 15:09

Byron Whitlock


You'll need to explicitly list the columns I think, so something along the lines of...

 DELETE FROM bar WHERE col1 LIKE '%foo%' OR col2 LIKE '%foo%'....etc 
like image 42
Paul Dixon Avatar answered Sep 18 '22 15:09

Paul Dixon