Adam Dedanga Adam Dedanga - 5 months ago 10
MySQL Question

MySQL - How to delete rows where column does not contain certain values?

I'm trying to delete all rows where a specific column does not contain certain strings.
Like this:

DELETE * FROM table
WHERE Disease NOT LIKE (Malaria, HIV, E. coli O157);


I get this error:
#1064 - You have an error in your SQL syntax; near '* FROM table WHERE Disease NOT LIKE (Malaria' at line 1

Answer

use

DELETE FROM TABLE_NAME WHERE Disease not in ('Malaria', 'HIV', 'E. coli 0157');

put your actual name of the table in place of TABLE_NAME in the above statement.