德瑪西亞99
2019-06-06 15:55:13
非IN子句和空值這個問題出現時,我得到了不同的記錄計數,我認為是相同的查詢之一使用not in where約束和另一個約束left join..的桌子not in約束有一個空值(壞數據),這將導致該查詢返回0條記錄的計數。我有點理解為什么,但是我需要一些幫助來充分理解這個概念。簡單地說,為什么查詢A返回一個結果而B不返回?A: select 'true' where 3 in (1, 2, 3, null)B: select 'true' where 3 not in (1, 2, null)這發生在SQLServer 2005上。我還發現set ansi_nulls off使B返回結果。
3 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
select 'true' where 3 = 1 or 3 = 2 or 3 = 3 or 3 = null
3 = 3
select 'true' where 3 <> 1 and 3 <> 2 and 3 <> null
ansi_nulls
3 <> null
ansi_nulls
3 <> null

繁花不似錦
TA貢獻1851條經驗 獲得超4個贊
3 = 1 or 3 = 2 or 3 = 3 or 3 = nullwhich is: FALSE or FALSE or TRUE or UNKNOWN which evaluates to TRUE
3 <> 1 and 3 <> 2 and 3 <> nullwhich evaluates to: TRUE and TRUE and UNKNOWN which evaluates to: UNKNOWN
select 'true' where 3 <> nullselect 'true' where not (3 <> null)

冉冉說
TA貢獻1877條經驗 獲得超1個贊
NOT IN
當與未知值比較時,返回0條記錄。
NULL
NOT IN
NULL
NULL
0
NULL
添加回答
舉報
0/150
提交
取消