NULL values are excluded. Why?

前端 未结 4 1839
谎友^
谎友^ 2020-12-16 11:47

This is about a bizarre behaviour I found in Microsoft Sql Server. Please correct me if I\'m wrong.

SELECT COUNT(*) FROM TABLEA 
WHERE [Column1] IS NULL;
         


        
4条回答
  •  隐瞒了意图╮
    2020-12-16 12:03

    SQL uses three valued logic.

    t1.[Column1] NOT IN ('Cross/Up sell', 'Renegotiation', 'Renewal') 
    

    is equivalent to

    t1.[Column1] <> 'Cross/Up sell' AND  
    t1.[Column1] <> 'Renegotiation' AND 
    t1.[Column1] <>  'Renewal')
    

    When t1.[Column1] is NULL this expression evaluates to UNKNOWN rather than TRUE so these rows are not returned.

    The only time NULL NOT IN ( ... ) will be returned is if the NOT IN clause evaluates to an empty set.

提交回复
热议问题