当前位置: 代码迷 >> Oracle管理 >> 数据库(记录),该如何解决
  详细解决方案

数据库(记录),该如何解决

热度:490   发布时间:2016-04-24 05:44:55.0
数据库(记录)
一个表中有若干相同的记录,用SQL语句怎么删除重复记录,只保留唯一一条呢?

------解决方案--------------------
方法一
先备份表,删除了重新插于
create table test as (select distinct * from test1)


truncate table test


insert into test select * from test1;

drop table test1

方法二
delete from test where rowid not in (select max(t1.rowid) from test1 t1 group by id,city,num)

------解决方案--------------------
delete from tab a where a.rowid not in (select max(rowid) from tab b where a.id=b.id)
  相关解决方案