Reputation: 569
I have a numeric column named id
in my table.
I want to select the queries which has id in 1,2,3 and the one which has 'null' in them.
I dont want to use the query like:
SELECT * FROM MYTABLE WHERE ID IN (1,2,3) OR ID IS NULL
Can I use something like :
SELECT * FROM MYTABLE WHERE ID IN (1,2,3,null)
Is this possible? The above query returns me the same result as for
SELECT * FROM MYTABLE WHERE ID IN (1,2,3)
Upvotes: 0
Views: 7043
Reputation: 4824
in sql server
SELECT * FROM MYTABLE WHERE isnull(ID,0) IN (1,2,3,0)
Upvotes: 0
Reputation: 6944
If you using oracle, this may be solution.
SELECT * FROM MYTABLE WHERE NVL(ID,-1) IN (1,2,3,-1)
Upvotes: 1
Reputation: 33457
You must use:
SELECT * FROM MYTABLE WHERE ID IN (1,2,3) OR ID IS NULL
NULL always requires the special handling of IS NULL.
Upvotes: 0
Reputation: 9188
Short answer? No. You must use the IS NULL
predicate. NULL != NULL (two NULL values are not necessarily equal), so any type of equals NULL
, in (..., NULL)
is not going to work.
Upvotes: 3