SELECT
*
FROM
users
WHERE
username IN ("john", "bob", "ray", "sexay")
Let’s say I have these in my table:
ID USERNAME
------------------
1 john
2 bob
3 jack
I want to know which of my set did not match, so I need "ray" and "sexay". Is there a pure SQL way of doing this? I know I can do this with multiple queries but I have 200 or so users and if it’s possible to do it in one query then great.
EDIT #1: A pure NOT IN is not sufficient because that would return all users that do not match my username set. I don’t need every single one, just every single username string in my given set that doesn’t match.
You need to restructure your query so that your list of values are in a derived table, at which point you can use one of the standard methods to test which values from one table are not in another. The standard approaches for doing this are:
Here is a example of NOT EXISTS:
Or with a join: