sql server 使用 not in 时 要注意null值问题 ?
求大神讲讲 两者的关系联系??
------解决方案--------------------
select 1 where 2 not in (3,null) --没有输出结果集
select 1 where 2 in (2,null) --输出1
------解决方案--------------------
T-SQL是三值逻辑,true、false和unknown,not true=false,not false=true,not unknown=unknown.
另外,in的本质就是or,or是短路逻辑,只要其中一个为true,整个谓词就为true,
所以:select 1 where 2 in (2,null) 为true,返回1
而:select 1 where 2 not in (3,null)
2不等于3,同时2和null也不能匹配,所以为false