Sunmit Girme
Sunmit Girme

Reputation: 569

SQL Select-IN query

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

Answers (4)

RoMEoMusTDiE
RoMEoMusTDiE

Reputation: 4824

in sql server

SELECT * FROM MYTABLE WHERE isnull(ID,0) IN (1,2,3,0)

Upvotes: 0

hkutluay
hkutluay

Reputation: 6944

If you using oracle, this may be solution.

SELECT * FROM MYTABLE WHERE NVL(ID,-1) IN (1,2,3,-1)

Upvotes: 1

Corbin
Corbin

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

RET
RET

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

Related Questions