A few months ago, when I called a senior friend, I asked a question: how can I delete all repeated records in a table? At that time, I never figured it out. Recently, I started learning ORACLESQL again. I thought about this problem and spent a lot of time thinking about it. Finally, I thought of a solution with my colleagues' reminders. SQL & gt; select * fromtemp; AABB & mdash; & mda
A few months ago, when I called a senior friend, I asked a question: how can I delete all repeated records in a table? At that time, I never figured it out.
I recently started to learn oracle SQL again. I thought about this problem and spent a lot of time thinking about it. Finally, I thought of a solution with my colleague's reminder.
SQL> select * from temp;
AA BB
------------
Abc
Abc
Xyz
Xyz
Opq
SQL> select max (rowid), aa, bb from temp group by aa, bb;
MAX (ROWID) AA BB
------------------
AAAMWPAABAAANlqAAB abc
AAAMWPAABAAANlqAAE opq
AAAMWPAABAAANlqAAD xyz
SQL> delete from temp where (rowid, aa, bb) not in (select max (rowid), aa, bb from temp group by aa, bb );
2 rows deleted.
SQL> commit;
Commit complete.
SQL> select * from temp;
AA BB
------------
Abc
Xyz
Opq
OK. After testing, the problem is solved. :) Happy ing