I want a query that retrieves the result of values if it doesn’t exist.
Example: select * from the table.A where column1 in (1,2,3)
If 2, 3 values exist then I will get 2 and 3 as a result.
But I need the values which are not available in the table i.e., 1.
Any help is much appreciated!
2
Answers
You can build a list of values like this:
And excluding one result from another one can be done using
EXCEPT
. See also the documentation.Together, you can do following:
So for example for this sample data:
The result of above query will be:
See this fiddle example
Your question is ambiguous, do you want:
null
for items that do not exist?If you are seeking the latter then you need to create an object containing the wanted values and then LEFT join the existing table. (See demo)
The CTE could be another table instead.