-- --标准sql方法:mysql、sql server--
-- 查询重复 方法一
select t.id,t.name from test t join(
select min(id) id,name from test group by name having(count(1)>1)
) tt on t.id>tt.id and t.name=tt.name
-- 查询重复 方法二
select * from test where exists(
select * from (
select min(id) id,name from test group by name having(count(1)>1)
) as tt where test.id>tt.id and test.name=tt.name
)
-- 删除重复 方法
delete from test where exists(
select * from (
select min(id) id,name from test group by name having(count(1)>1)
) as tt where test.id>tt.id and test.name=tt.name
)
-- --sql server方法----
-- 查询
select * from (
select ROW_NUMBER() over(partition by name order by id ) row,id,name from test
) t where t.row>1
-- 删除
delete from test where exists(
se
数据库数据删除重复数据
最新推荐文章于 2024-04-17 15:25:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)