表relation
create table relation( id int primary key auto_increment, userid int not null, fanid int not null );
插入几条数据
insert into relation(userid,fanid) values(1,1) ,(1,1) ,(1,1), (2,2),(2,2) ,(3,3),(3,3);
表中的数据
id | userid | fanid |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 1 | 1 |
4 | 2 | 2 |
5 | 2 | 2 |
6 | 3 | 3 |
7 | 3 | 3 |
去重
delete t from relation s join relation t using(userid,fanid) where s.id<t.id;
总结
以上所述是小编给大家介绍的mysql删除重复行的实现方法,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
荐 Mysql2020最新教程(高级部分)之存储引擎与简单的sql优化
大型互联网必问的MySQL面试题:MySQL存储与索引+事务和锁+性能优
网友评论