我在本地服务器上有一个简单的表。
mysql> desc table ;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(10) | YES | | NULL | |
| count | int(10) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec它只有三条记录。
mysql> select * from uday ;
+------+-------+
| id | count |
+------+-------+
| 1 | 1 |
| 2 | 2 |
| 3 | 0 |
| 4 | NULL |
+------+-------+
4 rows in set (0.00 sec)现在,为什么我在下面的结果中看不到第四列?
mysql> select * from uday where count NOT IN (0) ;
mysql> select * from uday where count != 0 ;
+------+-------+
| id | count |
+------+-------+
| 1 | 1 |
| 2 | 2 |
+------+-------+
2 rows in set (0.00 sec)第四张唱片怎么样……?它在结果中不可见。NULL不是0,对吗?
请忽略如果它看起来相当愚蠢,因为我甚至在编码部分没有竞争力。
发布于 2012-04-05 19:11:35
col1 not in (1,2,null)是以下的简写:
col1 <> 1 and col1 <> 2 and col1 <> null在SQL的three-valued logic中,col1 <> null返回unknown。true and true and unknown也返回unknown。由于where只接受true,而不接受unknown,因此会从结果集中过滤出带有null的行。
https://stackoverflow.com/questions/10027365
复制相似问题