唯一键肯定没问题。可以把你的问题数据和表结构截个图来看看。至于删除重复记录的语句,提个给你参考:
userid | ctime |
+--------+---------------------+
| 1 | 2015-12-09 10:34:26 |
| 1 | 2015-12-09 10:34:33 |
| 2 | 2015-12-09 10:34:35 |
| 2 | 2015-12-09 10:34:36 |
| 2 | 2015-12-09 10:34:36 |
| 2 | 2015-12-09 10:34:37 |
| 2 | 2015-12-09 10:34:38 |
delete from ttt where ctime not in (select ctime from (select userid,ctime from ttt group by userid having count(*)>1)b);
删除后:
userid | ctime |
+--------+---------------------+
| 1 | 2015-12-09 10:34:26 |
| 2 | 2015-12-09 10:34:35 |
userid | ctime |
+--------+---------------------+
| 1 | 2015-12-09 10:34:26 |
| 1 | 2015-12-09 10:34:33 |
| 2 | 2015-12-09 10:34:35 |
| 2 | 2015-12-09 10:34:36 |
| 2 | 2015-12-09 10:34:36 |
| 2 | 2015-12-09 10:34:37 |
| 2 | 2015-12-09 10:34:38 |
delete from ttt where ctime not in (select ctime from (select userid,ctime from ttt group by userid having count(*)>1)b);
删除后:
userid | ctime |
+--------+---------------------+
| 1 | 2015-12-09 10:34:26 |
| 2 | 2015-12-09 10:34:35 |