0

I'm using PHP but that's not important. I have a variable that contains a standard array of positive int IDs. And I want to do a SELECT query with this array against a MySQL table to find out what IDs are not already existing in the data table. My first thought was to use IN() but then I realized that doing it that way I can only get a list of IDs that do exist not ones that don't. Of course with a list of IDs that do exist, I could compile it into a second array and then use array_diff() but I can't help wondering if there's another way to do it.

4
  • @PHPgrur select * from table while IDs NOT IN ('1','2'); have you tried this?
    – bassxzero
    Apr 11, 2015 at 18:30
  • I think he wants to return all IDs in his list minus the ones that appear in the table.
    – aleju
    Apr 11, 2015 at 18:34
  • That's not what I was looking for. I want a list of IDs from my array that do not exist in the database.
    – PHPguru
    Apr 11, 2015 at 18:35
  • You can use NOT IN instead of IN.
    – Havenard
    Apr 11, 2015 at 22:57

1 Answer 1

0

I decided to use unset()

SELECT QUERY
where (row) {
   unset(id)
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.