Is there a better way to achieve this same result?
I have a list of IDs (not in a table). I need to find which of the IDs does not exist in a given table. I’ve been able to achieve the results I’m looking for by executing the following SQL statement:
SELECT InlineID
FROM (SELECT 11111 AS InlineID UNION ALL SELECT 22222 UNION ALL SELECT 33333) AS Ids
LEFT OUTER JOIN MyTable ON Ids.InlineID = MyTable.ID
WHERE MyTable.ID IS NULL;
While this works, it feels as though there ought to be a simpler way to achieve the same result, i.e. the repetitive UNION ALL statements look messy, especially when the list of IDs grows large. One other restriction is that I don’t have rights to be able to create temp tables, so those types of solutions will not be possible.
1 Answer