4

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The character '*' is not valid in SQLite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.