MySQL(mariadb)奇怪的VARCHAR WHERE NULL行为[重复](MySQL (mariadb) strange VARCHAR WHERE NULL behaviour [dupl

编程入门 行业动态 更新时间:2024-10-21 09:14:17
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 answers

I have a table like:

id name (varchar) -------------------------- 1 test 2 some 3 NULL 4 test

when I query

SELECT * FROM table WHERE name != 'some';

I get the result:

id name -------------------------- 1 test 4 test

Why 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 NULL

Because comparing with NULL results in UNKNOWN. You have to use the IS operator.

SELECT * FROM table WHERE name != 'some' OR name IS NULL

更多推荐

本文发布于:2023-07-25 05:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256767.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:奇怪   VARCHAR   MySQL   mariadb   behaviour

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!