【发布时间】:2016-01-25 09:46:15
【问题描述】:
有一张桌子,
root@localhost:[test]05:35:05>desc t;
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| studio_id | char(32) | YES | | NULL | |
+-----------+----------+------+-----+---------+----------------+
有两行:
root@localhost:[test]05:35:29>select * from t;
+----+----------------------------------+
| id | studio_id |
+----+----------------------------------+
| 1 | foo1 |
| 2 | 299a0be4a5a79e6a59fdd251b19d78bb |
+----+----------------------------------+
发现了一些奇怪的查询现象,例如
# I can understand this
root@localhost:[test]05:37:00>select * from t where studio_id = '0';
Empty set (0.00 sec)
# I also understand this
root@localhost:[test]05:41:45>select * from t where studio_id = 1;
Empty set, 2 warnings (0.00 sec)
# but I can't understand this
root@localhost:[test]05:36:21>select * from t where studio_id = 0;
+----+-----------+
| id | studio_id |
+----+-----------+
| 1 | foo1 |
+----+-----------+
为什么会返回记录,为什么只返回foo1,299a0be4a5a79e6a59fdd251b19d78bb 呢?
root@localhost:[test]05:38:20>select * from t where studio_id <> 0;
+----+----------------------------------+
| id | studio_id |
+----+----------------------------------+
| 2 | 299a0be4a5a79e6a59fdd251b19d78bb |
+----+----------------------------------+
【问题讨论】:
-
确实很奇怪,当
foo1的 id 为 2 时,它返回 id 2:sqlfiddle.com/#!9/8f8a7/1 -
这里有一个线索...sqlfiddle.com/#!9/8f8a7/5
-
@11mb 和草莓 谢谢!让我知道可以在线运行 sql