Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 当不在内部查询包含值“NULL”时,为什么结果集为空?_Mysql_Sql - Fatal编程技术网

Mysql 当不在内部查询包含值“NULL”时,为什么结果集为空?

Mysql 当不在内部查询包含值“NULL”时,为什么结果集为空?,mysql,sql,Mysql,Sql,这是我的mysql表,名为samp 当我使用类似select name from samp的查询时,其中名称不在'alki','pri',NULL中 我希望结果是, +--------+ | name | +--------+ | karthi | | aadhil | +--------+ 但我的结果是空集。我有另一个选择。但是我需要知道这背后的原因。你可以在下面试试 select name from samp where name not in ('alki','pri') and n

这是我的mysql表,名为samp

当我使用类似select name from samp的查询时,其中名称不在'alki','pri',NULL中

我希望结果是,

+--------+
| name   |
+--------+
| karthi |
| aadhil |
+--------+
但我的结果是空集。我有另一个选择。但是我需要知道这背后的原因。

你可以在下面试试

select name from samp where name not in ('alki','pri') and name is not null
你可以在下面试试

select name from samp where name not in ('alki','pri') and name is not null
这就是NULL的行为方式。它在设计上无法与任何东西相比。您的查询被解释为:

select name
from samp
where name <> 'alki'
and name <> 'pri'
and name <> NULL
由于name既不等于也不等于NULL,因此不满足该条件。

这就是NULL的行为方式。它在设计上无法与任何东西相比。您的查询被解释为:

select name
from samp
where name <> 'alki'
and name <> 'pri'
and name <> NULL
由于name not equals not equal NULL,因此不满足该条件。

NULL表示未知,它不是一个值,您需要使用not NULL而不是在NULL中使用

你可以试试这个

select name from samp where name not in ('alki','pri') and name is not null
NULL表示未知。它不是一个值,您需要使用notnull而不是在NULL中使用

你可以试试这个

select name from samp where name not in ('alki','pri') and name is not null
您可以简单地执行以下操作:

select name
from samp
where name not in ('alki', 'pri');
NULL不在中失败,就像它在大多数其他比较中失败一样

如果明确希望包含NULL,则需要将其包含为:

select name
from samp
where name not in ('alki', 'pri') or name is null;
您可以简单地执行以下操作:

select name
from samp
where name not in ('alki', 'pri');
NULL不在中失败,就像它在大多数其他比较中失败一样

如果明确希望包含NULL,则需要将其包含为:

select name
from samp
where name not in ('alki', 'pri') or name is null;

当查询是select name from samp,其中name不在'alki'、'pri'中时,结果是什么?仅供参考:我得到了我的预期结果。但是如果内部查询返回一个包含“NULL”的结果怎么办?看看@Pham X.Bach提供的链接。它很好地解释了为什么你会得到这样的结果。这是一个常见的问题,源于不理解NULL是如何工作的。当查询是select name from samp,其中name不在'alki'、'pri'中时,结果会是什么?仅供参考,您可以参考:我得到了预期的结果。但是如果内部查询返回一个包含“NULL”的结果怎么办?看看@Pham X.Bach提供的链接。它很好地解释了为什么你会得到这样的结果。这是一个常见的问题,源于不理解NULL是如何工作的。是的。它会起作用的。但是为什么只包含NULL会使我的结果为空。我需要知道那里发生了什么。首先,NULL不是一个值,它是表示空的标记,这就是为什么当你需要与NULL值进行比较时,你需要使用is NULL或is not NULL@PRIYAMAs fa06说,[name]=NULL检查将始终是假的,[name]NULL检查也是假的,因为你不能与NULL进行比较,所以这是在搞乱你的逻辑。如果您确实从samp中选择了name,其中name不在子查询中,或者0=从子查询中选择count1,那会怎么样?希望这是有意义的,没有子查询的细节,很难获得更多specific@PRIYAM我重复一遍,上面给你的链接将详细解释你问题的答案。所以,如果你想知道那里发生了什么,请去看看。除IS null外,还包含null的表达式将返回的实际值未知,其计算结果通常为false。@BobRodes是的,链接详细帮助了我。。我明白到底发生了什么,是的。它会起作用的。但是为什么只包含NULL会使我的结果为空。我需要知道那里发生了什么。首先,NULL不是一个值,它是表示空的标记,这就是为什么当你需要与NULL值进行比较时,你需要使用is NULL或is not NULL@PRIYAMAs fa06说,[name]=NULL检查将始终是假的,[name]NULL检查也是假的,因为你不能与NULL进行比较,所以这是在搞乱你的逻辑。如果您确实从samp中选择了name,其中name不在子查询中,或者0=从子查询中选择count1,那会怎么样?希望这是有意义的,没有子查询的细节,很难获得更多specific@PRIYAM我重复一遍,上面给你的链接将详细解释你问题的答案。所以,如果你想知道那里发生了什么,请去看看。除IS null外,还包含null的表达式将返回的实际值未知,其计算结果通常为false。@BobRodes是的,链接详细帮助了我。。我明白到底发生了什么。