4.16 删除重复记录
Posted 长城之上是千亿的星空,星空之上是不灭的守望。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4.16 删除重复记录相关的知识,希望对你有一定的参考价值。
从表中删除重复记录,考虑如下所示的表:
create table dupes (id integer,name varchar(10));
insert into dupes values (1,‘NOPOLEON‘);
insert into dupes values (2,‘DYNAMITE‘);
insert into dupes values (3,‘DYNAMITE‘);
insert into dupes values (4,‘SHE SELLS‘);
insert into dupes values (5,‘SEA SHELLS‘);
insert into dupes values (6,‘SEA SHELLS‘);
insert into dupes values (7,‘SEA SHELLS‘);
select * from dupes order by 1;
+------+------------+
| id | name |
+------+------------+
| 1 | NOPOLEON |
| 2 | DYNAMITE |
| 3 | DYNAMITE |
| 4 | SHE SELLS |
| 5 | SEA SHELLS |
| 6 | SEA SHELLS |
| 7 | SEA SHELLS |
+------+------------+
解决方案:
delete from dupes
where id not in
(select minid from
(select min(id) as minid from dupes group by name)
b);
以上是关于4.16 删除重复记录的主要内容,如果未能解决你的问题,请参考以下文章