views:

223

answers:

1

Say I have a table with an ID field, and I have a local array (in any language, php or objective c or basic or whatever) of eligible IDs. I want to delete any record in which the ID field does not match any of the eligible IDs in my array.

Is there any way to do this in a single SQL query? Can you pass an array into SQL and basically say delete from sometable where 'id' is not in 'arrayofids'?

Thanks for any help. I've looked into the help docs but SQLite/SQL aren't one of my best skills.

A: 

I think I've already found the answer:

$locationSQL = "DELETE * FROM item WHERE 'ID' NOT IN ($somearray)"; 

And you simply use commas to separate the items of the array. Simple enough.

mjdth