IN Operator SQL

后端 未结 7 1513
庸人自扰
庸人自扰 2020-12-11 22:21

I have a table called NUMS with a single column n.
And I fill values 1,2,3,4,5,null in it.

Now a query

SELECT n FROM Nums 
 WHERE n IN (1, 2,         


        
7条回答
  •  醉梦人生
    2020-12-11 23:24

    I am also comparing n with a null value which should yield unknown and it should return an empty set.

    it shouldn't if you need in additional row filled with NULL values the best way imo is:

    SELECT n FROM Nums WHERE n IN(1,2)
    UNION
    SELECT NULL
    

    Now a query

    SELECT n FROM Nums WHERE n NOT IN(1, 2, null)

    ...gets converted to:

    Here what I said above works and it does not return anything.

    thats right, because nothing can be equal to NULL and for NULL comparison IS NULL statement is used

提交回复
热议问题