id | name |
1 | mike |
2 | jack |
3 | NULL |
select name form table where name !='jack';
该语句只能查出第1行,也就是mike;
select name form table where name !='jack' or name is null;
该语句可以查出第1行和第3行,也就是mike和NULL;
总结:也就是说,!= 和=用来判断具体的值,而NULL需要用is或者is not判断(只能用is或is not,且like或not like不能判断)
如果你一定想要使用 != Null来判断,需要加上这个语句:
set ANSI_NULLS off
这时会发现 is not NULL 和 != null 是等效的。