mysql删除重复行的实现方法

2023年 4月 28日 15.5k 0

表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 u

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

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论