NULL 不等于 2 为真?

若是你曾经在SQL语句里面有下面查询ide

select * from table1 where a<>2 blog

而a 为null时,你会发现没有结果出来,按照常理,Null是空值,确定不等于2,因此上面这个查询应该返回符合条件的全部值,但实际却没有返回。get

最快的例子是下面这句SQL,结果是无值输出,正常应该输出1. 那么这类问题怎么解决? it

select 1 where null<>2 table

 

image

 

第一种:不使用<>class

select * from table1 where not (a=2)select

第二种:使用isnull替换null值。im

select * from table1 where isnull( a,-1)<>2查询

相关文章
相关标签/搜索