当我们使用mysql的!=的时候,要注意一点的是!=只会筛选该字段非空的数据,如果查询的表中有字段为null,这些数据都不会被查询出来,即时他!=某个数据
例如:
select * from test where type != 2
test表中 type 存在 1 ,2,null
那么该查询语句只会筛选出type为1的数据,即使 null也不等于2
建议使用:
select * from test where (type != 2 or type is null)
或者
select * from test where ifnull(type,"")!= 2