MySQL中NULL判断

查询某个字段不为NULL,使用如下语句时MySQL解析器会将字段为null的数据也当做满足不等于的条件而将数据筛选掉。

select * from tb_emp where comm <> null

正确的做法是:

select * from tb_emp where comm is not null

结论:
对NULL进行判断处理时,只能采用IS NULL或IS NOT NULL,而不能采用=, <, <>, !=

发布了460 篇原创文章 · 获赞 812 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/lianghecai52171314/article/details/105584034