MySQL(mariadb)奇怪的VARCHAR WHERE NULL行为[重复](MySQL (mariadb) strange VARCHAR WHERE NULL behaviour [duplicate])
这个问题在这里已有答案:
MySQL:选择列为空的行 8个答案我有一张桌子:
id name (varchar) -------------------------- 1 test 2 some 3 NULL 4 test当我查询
SELECT * FROM table WHERE name != 'some';我得到了结果:
id name -------------------------- 1 test 4 test为什么它不返回name == NULL的行?
服务器版本:5.5.31-MariaDB-1~pqueeze-log - mariadb.org二进制发行版(协议版本10)
客户端版本:libmysql - 5.1.66(mysqli)Protokoll版本:10
This question already has an answer here:
MySQL: selecting rows where a column is null 8 answersI have a table like:
id name (varchar) -------------------------- 1 test 2 some 3 NULL 4 testwhen I query
SELECT * FROM table WHERE name != 'some';I get the result:
id name -------------------------- 1 test 4 testWhy it doesn't return the rows with name == NULL ?
Server Version: 5.5.31-MariaDB-1~squeeze-log - mariadb.org binary distribution (protocol version 10)
Client Version: libmysql - 5.1.66 (mysqli) Protokoll-Version: 10
最满意答案
因为与NULL比较导致UNKNOWN 。 您必须使用IS运算符。
SELECT * FROM table WHERE name != 'some' OR name IS NULLBecause comparing with NULL results in UNKNOWN. You have to use the IS operator.
SELECT * FROM table WHERE name != 'some' OR name IS NULL更多推荐
发布评论