AND字段NOT IN(NULL)返回一个空集

编程入门 行业动态 更新时间:2024-10-09 05:18:55
本文介绍了AND字段NOT IN(NULL)返回一个空集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此查询为什么返回一个空集:

Why does this query returns an empty set:

select p.iuser_id,p.produit_id from portefeuille p WHERE produit_id=48 AND p.iuser_id NOT IN (NULL);

而这个:

select p.iuser_id,p.produit_id from portefeuille p WHERE produit_id=48 LIMIT 5

返回结果,例如

72968, 48 106967, 48 7381, 48 81678, 48 194250, 48

,并且这些值都不为NULL或应等于NULL. (为了简洁起见,我添加了限制5,并且我正在使用MySql 5.1)

and none of those values are NULL or should be equal to NULL. (I added limit 5 for consiseness, and I am using MySql 5.1)

edit:在这里,我将问题缩小为NOT IN(NULL).原始查询有一个子查询,其中某些行包含NULL,如下所示:

edit: Here I narrowed the problem down to NOT IN(NULL). The original query had a subquery with some of the rows containing NULL as such:

WHERE user_id NOT IN( select user_id from mailsubscriptions )

和一些user_id为NULL,但是集合中只有一个NULL会污染整个查询.

and some user_id were NULL, but only one NULL in the set contaminates the whole query.

推荐答案

x NOT IN(...)被定义为x与子查询返回的每个值之间的一系列比较. SQL使用三值逻辑,逻辑表达式的三个可能值为 true , false 或 unknown .值与NULL的比较为未知,如果那些NOT IN比较中的任何一个为未知,则结果也被视为未知

x NOT IN (...) is defined as a series of comparisons between x and each of the values returned by the subquery. SQL uses three-value logic, for which the three possible values of a logical expression are true, false or unknown. Comparison of a value to a NULL is unknown and if any one of those NOT IN comparisons is unknown then the result is also deemed to be unknown.

更多推荐

AND字段NOT IN(NULL)返回一个空集

本文发布于:2023-07-21 07:22:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1175407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空集   字段   NULL

发布评论

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

>www.elefans.com

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