复现:

CREATE TABLE `t1` (
  `user_id` int DEFAULT NULL,
  `name` varchar(10) DEFAULT NULL,
  `address` varchar(10) DEFAULT NULL,
  KEY `idx_userid` (`user_id`)
) ENGINE=InnoDB
mysql> select * from t1;
+---------+------+---------+
| user_id | name | address |
+---------+------+---------+
|      10 | aa   | bj      |
|      20 | bb   | sh      |
|      30 | cc   | NULL    |
+---------+------+---------+
3 rows in set (0.00 sec)

查询不等于台湾的数据

mysql> select * from t1 where address != 'taiwan';
+---------+------+---------+
| user_id | name | address |
+---------+------+---------+
|      10 | aa   | bj      |
|      20 | bb   | sh      |
+---------+------+---------+
2 rows in set (0.06 sec)

mysql> select * from t1 where address <> 'taiwan';
+---------+------+---------+
| user_id | name | address |
+---------+------+---------+
|      10 | aa   | bj      |
|      20 | bb   | sh      |
+---------+------+---------+
2 rows in set (0.00 sec)

按照人类的思维应该返回3条数据,但却返回了2条数据。

一个诡异的SQL返回结果,可作为面试题_数据

结论

在MySQL中,查找“没有特定值的数据”将不包含NULL