How to delete a repetition record in Oracle?

xiaoxiao2021-03-06  51

The table T structure is as follows

COL1 col2 col3

There are repetitive records (COL1, COL2 primary key), how to delete

1, have a few repeat records (there is index on col1, COL2)

Delete T Where (Col1, Col2) in (Select Col1, Col2 from T Group By Col1, Col2 Having Count (*)> 1) And Rowid Not in (SELECT MIN (Rowid) from T Group By Col1, Col2 Having Count (* )> 1)

2, most records have repeated records

Delete T WHERE ROWID NOT IN (SELECT MIN (ROWID) from t group by col1, col2)

3, other writing

Delete t where rowid in (SELECT A.ROWID FROM T A, T B WHERE A.COL1 = B.COL1 and A.COL2 = B.COL2 and A.ROWID> B.ROWID)

转载请注明原文地址:https://www.9cbs.com/read-116826.html

New Post(0)