Mysql中有重复的数据:

select resource_id,count(1) from t_resource_apptype_releation  GROUP BY resource_id having count(1)>1 order by count(1) desc

删除一下吧:

delete a from t_resource_apptype_releation as a,
(
select *,min(id) from t_resource_apptype_releation group by resource_id having count(1) > 1
) as b
 where a.resource_id = b.resource_id and a.id > b.id;

创建一个唯一索引,防止再发生类似事件。

 删除重复记录(Mysql,SqlServer,Sqlite)

 

现在开始玩SQL SERVER 

查看:

select resource_id,count(1) from t_resource_apptype_releation  GROUP BY resource_id having count(1)>1 order by count(1) desc 

删除:

delete aa from t_resource_apptype_releation aa where  exists(select * from t_resource_apptype_releation where aa.id>id and  resource_id=aa.resource_id)

删除重复记录(Mysql,SqlServer,Sqlite)

 

Sqlite这样:

delete from T_RESOURCE_APPTYPE_RELEATION where id not in (select min(id) from T_RESOURCE_APPTYPE_RELEATION  group  by resource_id);

 

相关文章:

  • 2021-10-29
  • 2021-09-22
  • 2021-12-18
  • 2021-10-14
  • 2021-06-06
  • 2022-03-10
  • 2021-12-28
  • 2022-02-25
猜你喜欢
  • 2021-07-19
  • 2022-12-23
  • 2022-01-15
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案