Reputation: 6546
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 ID
s. I want to delete any record in which the ID
field does not match any of the eligible ID
s 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.
Upvotes: 4
Views: 3804
Reputation: 6546
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.
Upvotes: 4