有一个表申请,在条件比较焦炭MySQL查询的一些现象与诠释0
[email protected]:[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 | |
+-----------+----------+------+-----+---------+----------------+
有两行:
[email protected]:[test]05:35:29>select * from t;
+----+----------------------------------+
| id | studio_id |
+----+----------------------------------+
| 1 | foo1 |
| 2 | 299a0be4a5a79e6a59fdd251b19d78bb |
+----+----------------------------------+
发现了一些奇怪的现象查询,例如
# I can understand this
[email protected]:[test]05:37:00>select * from t where studio_id = '0';
Empty set (0.00 sec)
# I also understand this
[email protected]:[test]05:41:45>select * from t where studio_id = 1;
Empty set, 2 warnings (0.00 sec)
# but I can't understand this
[email protected]:[test]05:36:21>select * from t where studio_id = 0;
+----+-----------+
| id | studio_id |
+----+-----------+
| 1 | foo1 |
+----+-----------+
为什么可能返回的记录,为什么只有foo1
回来,那299a0be4a5a79e6a59fdd251b19d78bb
?
[email protected]:[test]05:38:20>select * from t where studio_id <> 0;
+----+----------------------------------+
| id | studio_id |
+----+----------------------------------+
| 2 | 299a0be4a5a79e6a59fdd251b19d78bb |
+----+----------------------------------+
奇怪的是,当'foo1'有id时,它返回id 2 2:http://sqlfiddle.com/#!9/8f8a7/1 – 11mb
这是一个线索...... http://sqlfiddle.com/# !9/8f8a7/5 – Strawberry
@ 11mb和草莓谢谢!让我知道可以在线运行sql – zhuguowei