How to delete a duplicate records in a table without using rowid

Showing Answers 1 - 11 of 11 Answers

Krishnakant Mahamuni

  • Sep 14th, 2006
 

The following query can be used to delete the duplicate rows without using rowid.

DELETE FROM TABLENAME WHERE (COLUMNS-TO-COMPARE) IN (SELECT COLUMNS-TO-COMPARE FROM TABLENAME GROUP BY COLUMNS-TO-COMPARE HAVING COUNT(*) > 1) AND ROWNUM < ( SELECT COUNT(*) FROM  TABLENAME GROUP BY COLUMNS-TO-COMPARE HAVING COUNT(*) > 1


Thanks & Regards,
Krishnakant Mahamuni.

 

  Was this answer useful?  Yes

Sasi

  • Sep 15th, 2006
 

Can u plz explain this

  Was this answer useful?  Yes

bhargav

  • Nov 26th, 2006
 

     To eliminate duplicate records there are Three Methods ..

1) using rowid:

        Delete from <tablename> a where rowid > (

       Select min(rowid) from <tablename> B where a.keyvalues=b.keyvalues );

                  In the above query Keyvalues means column names which we have to compare.

2) Creating another table

 create table <tablename2> as select distinct *from <tablename1>;

 drop <tablename1>

 rename <tablename2> to <tablename1>;

  Remember to recreate all indexes, constrains ,triggers ..etc on the table

3) using rowid:

  Delete from <tablename> a

  where exists(select 'x' from <tablename> b

                     where b.keyvalue1=a.keyvalue2 and

                              b.keyvalue2=b.keyvalue2 and

                              b.rowid>a.rowid );

Karthik

  • Mar 13th, 2007
 

Hi,

If you have primary key Constrains in the table



Following is query will select the duplicate

----------------------------------------
Select * from X a, X b

Where a.1 != b.1 ( Primary Key)

And a 2 = b.2 (Equate All other columns)

Delete Statement:-

-----------------
Delete from X a, X b

Where a.1 <> b.1 (Primary Key Column)

And a 2 = b.2 (Equate All other columns)


Thanks
karthi

  Was this answer useful?  Yes

Delete from table_name where rownum in (select min(rownum) from table_name group by column2,column3);

where column2 and column3 are repeating columns.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions