Tortooga Tortooga - 1 year ago 84
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 Source

This would simply be:

delete t
     where t.customername not in (<list to keep>);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download