Search code examples
phpmysqlsql-delete

Delete Row if string is found in any columns


My comment database just got slammed with over 11,000 spam entries. I am trying to think of a way to delete any entry with a specific word in it. There are about 12 columns per entry and I want to search all of those columns and if there are any of the "keywords" in there then delete that row. Something like:

$sql = "DELETE FROM comments WHERE colum1, column2, column3 = has the substring xanaxs;"

Please help so I don't have to delete 11,000 rows.


Solution

  • You could concatenate all the columns together:

    $sql = "DELETE FROM comments WHERE concat(column1,column2,column3) like "%xanaxs%";