Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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 如果我使用IN运算符来过滤空值和空格,它不起作用为什么?_Mysql - Fatal编程技术网

Mysql 如果我使用IN运算符来过滤空值和空格,它不起作用为什么?

Mysql 如果我使用IN运算符来过滤空值和空格,它不起作用为什么?,mysql,Mysql,我有一张像这样的桌子 表1ID int,名称VC,说明VC; 此表包含100条记录。对于描述列,它有一些空格和空值。我想消除描述值为空或空白的行 我试过这样做 select * from table1 where description not in('',NULL); //Displaying nothing But select * from table1 where description in('',NULL);// It is displaying all the rows whi

我有一张像这样的桌子 表1ID int,名称VC,说明VC; 此表包含100条记录。对于描述列,它有一些空格和空值。我想消除描述值为空或空白的行

我试过这样做

select * from table1 where description not in('',NULL); //Displaying nothing

But

select * from table1 where description in('',NULL);// It is displaying all the rows which contains white spaces but not Nulls
我很困惑。在operator accepts varchar中,如果我不使用NOT,我会得到正确的结果,但是如果我不使用NOT,为什么我得不到正确的结果呢

提前感谢..

试试这个:


从表1中选择*,其中说明不在且说明不为空

您需要使用IS NOT NULL来比较NULL值

select * from table1 where description is not null and description <> ''

因为SQL IN条件有助于减少使用多个SQL或条件的需要

因此,写:

description not in('',NULL);
这与:

!(description='' OR description is NULL)
那也一样写:

!(description='') AND description is not NULL

可以试试这个-这将类似于c.IsNullOrWhitespace


从表1中选择*,其中说明不为空,并且LENTRIMDescription>0

SELECT*表1不正确。应该是从表1中选择*从我的测试中,两个查询都不适用于空部分。您可能需要检查您得到的结果。在IN中使用NULL不会使任何字段与我的NULL匹配。正如其他海报所述,NULL被视为特殊情况运算符,应与is NULL或is NOT NULL一起使用。您已从OP.select*FORM Table1复制了打字错误。它正在工作,但请您解释一下,如果我在中使用NULL,它为什么不能给出正确的结果。实际上,IN的目的是使用多个值并减少倍数或s。是的,IN的目的是提供多个值。但是null是一种特殊情况,需要特别处理。所以,当比较逻辑不是时,我们需要使用的空值不是null@Chella不,我们不能把空和等号比较。是的,我现在知道了。非常感谢。