Reputation: 7357
I'm doing an audit of one of my Android apps, and I noticed something peculiar.
I have a list of IDs, and I want to remove all rows from a table that don't have an _id in that list.
I would think the correct syntax be:
DELETE FROM table WHERE _id NOT IN...
However, my code has:
DELETE FROM table WHERE NOT _id IN...
Are these equivalent, or will the second statement do something unexpected?
Upvotes: 2
Views: 42
Reputation: 35790
Basics of boolean algebra https://en.m.wikipedia.org/wiki/De_Morgan%27s_laws
id in(x1,x2,...xn) means
id = x1 or id = x2 or ... id = xn
id not in(x1,x2,...xn) means
id <> x1 and id <> x2 and ... id <> xn
not id in(x1,x2,...xn) means
not(id = x1 or id = x2 or ... id = xn) that means
not(id = x1) and not(id = x2) and ... not(id = xn) that means
id <> x1 and id <> x2 and ... id <> xn
So they are the same.
Upvotes: 2