呵呵,这个问题不简单。如果这个表真的只有这两列就很难。记得ORACLE有个自动产生的表示行号的字段,好是ROWID吧,暂时就以它表示吧。下面的你可以试下,当然也可以根据实际情况改改,原理就是这样。
delete from students
where rowid =(select max(rowid) from students
where name in (select name from students
group by name
having count(*)>1)
)
如果有其他的列可以起到ROWID列的作用,那么就用那列代替ROWID;如果重复的行超过2行就重复运行上面的SQL。
delete from students
where rowid =(select max(rowid) from students
where name in (select name from students
group by name
having count(*)>1)
)
如果有其他的列可以起到ROWID列的作用,那么就用那列代替ROWID;如果重复的行超过2行就重复运行上面的SQL。
where rowid< (select max(rowid) from table_name
where column1=a.column1 and column2=a.column2
and colum3=a.colum3 and ...); ---- 不过,当表比较大(例如50万条以上)时,这个方法的效率之差令人无法忍受,需要另想办法