查找违反唯一约束的重复行

时间:2016-04-22 05:24:10

标签: mysql unique-constraint

mysql> select user_id, content_type_id, object_id, count(*) as num 
from vote_vote group by user_id, content_type_id, object_id 
having num > 1;

+----------+-----------------+-----------+-----+
| user_id  | content_type_id | object_id | num |
+----------+-----------------+-----------+-----+
| 25754992 |             961 |   3665767 |   2 |
| 38896810 |             961 |   3733660 |   3 |
+----------+-----------------+-----------+-----+

唯一键显示在“show create table”

UNIQUE KEY `user_id` (`user_id`,`content_type_id`,`object_id`),

我的问题: 怎么会发生这种情况? 为什么唯一键在这些记录上不起作用

一些更奇怪的结果:

enter image description here

show create table输出:

enter image description here

0 个答案:

没有答案