How to delete from a table where ID is in a list of IDs?

leora picture leora · Apr 11, 2010 · Viewed 122.9k times · Source

if I have a list of IDs (1,4,6,7) and a db table where I want to delete all records where ID is in this list, what is the way to do that?

Answer

Matti Virkkunen picture Matti Virkkunen · Apr 11, 2010

Your question almost spells the SQL for this:

DELETE FROM table WHERE id IN (1, 4, 6, 7)