将表中的记录id相同的删去重复的记录,只保存一条
附sql脚本:
prompt PL/SQL Developer import file
prompt Created on 2009年7月11日 星期六 by Administrator
set feedback off
set define off
prompt Disabling triggers for TEST...
alter table TEST disable all triggers;
prompt Loading TEST...
insert into TEST (ID, NAME)
values (100, 'aaa');
insert into TEST (ID, NAME)
values (101, 'bbb');
insert into TEST (ID, NAME)
values (103, 'ccc');
insert into TEST (ID, NAME)
values (105, 'ddd');
insert into TEST (ID, NAME)
values (104, 'eee');
insert into TEST (ID, NAME)
values (102, 'fff');
insert into TEST (ID, NAME)
values (102, 'ggg');
insert into TEST (ID, NAME)
values (101, 'hhh');
insert into TEST (ID, NAME)
values (105, 'iii');
commit;
prompt 9 records loaded
prompt Enabling triggers for TEST...
alter table TEST enable all triggers;
set feedback on
set define on
prompt Done.

解决方案 »

  1.   

    select id,name 
    from
    (select id,name,row_number() over(partition by id order by name) rn from test) t where  rn=1
      

  2.   

    相同的id,name不一样,你只要保留一条,具体怎么保留法,保留哪一条,还是随便要搞清楚
      

  3.   

    去重,但name的字段不一样哦,要保留哪个条呢,还是随即保留一条而已?
      

  4.   

    要是随机删除的话可以取rowid的最大或最小值来实现。
      

  5.   

    是不是可以用distince关键字实现,select (distinct id,name) from ……
      

  6.   

    select distinct a.id,a.name from test a,test b where a.id=b.id and a.rowid<b.rowid;
      

  7.   

    name字段的值不一样,保留哪一条?
      

  8.   

    附议11楼
    delete from test where rowid not in (select min(rowid) from test group by id);
      

  9.   

    delete from test
    where 
    id in (
         select max(id)
           from test
       group by id
    )
      

  10.   

    支持这种写法delete from test where rowid not in (select min(rowid) from test group by id); 
      

  11.   

    delete from test a where a.rowid>(select min(b.rowid) from test b where b.rowid=a.rowid)
      

  12.   

    ls的 你那样写 有问题呀delete from test a from a.rowid > (select min(b.rowid) from test b where a.id = b.id);
      

  13.   

    delete test a where exists(select 1 from test where id=a.id and name>a.name);
      

  14.   

    delete from test a where rowid not in (
    select max(b.rowid)
    from test b where a.id=b.id)
      

  15.   

    delete from test where rowid in ( 
    select max(b.rowid) from test group by id having count(*)>=2);多次执行;
      

  16.   

    以上全错,我这才是正确嘀:
    delete from test where rowid in ( 
    select max(rowid) from test group by id having count(*)>=2); 多次执行!
      

  17.   

    删除:
    delete from test where rowid in ( 
    select max(rowid) from test group by id having count(*)>=2); 查找
    select id,name 
    from 
    (select aa,bb,row_number() over(partition by id order by name) rn from test) t where  rn=1 
      

  18.   


    delete test t where id not in(select max(rowid) from test where id=t.id);
      

  19.   


    delete test t where rowid not in(select max(rowid) from test where id=t.id);