Tortooga Tortooga - 2 months ago 6
MySQL Question

Delete all entries which are not in "include" list

I have a column called "CustomerName" with text data. I also have a list of Customer Names which I want to keep. I want to execute a query that deletes the entire row of data if the CustomerName is not on my aforementioned keeper-list.

So basically I want to purge all the entries pertaining to customers not on my keeper-list.

Is there a way to do this in a single SQL query?

Answer

This would simply be:

delete t
     where t.customername not in (<list to keep>);
Comments