服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Mysql - mysql删除重复行的实现方法

mysql删除重复行的实现方法

2019-07-07 15:18勇敢的飞石 Mysql

这篇文章主要介绍了mysql删除重复行的实现方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

表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删除重复行的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

延伸 · 阅读

精彩推荐