How do I eliminate the duplicate rows

Showing Answers 1 - 35 of 35 Answers

AjayLebaka

  • Mar 26th, 2005
 

DELETE TableName WHERE rowid NOT IN ( SELECT MIN(rowid) FROM TableName GROUP BY ColumnName );

  Was this answer useful?  Yes

j Lehew

  • Aug 25th, 2005
 

Use the DISTINCT keyword right after SELECT... 
 
i.e. SELECT DISTINCT customername FROM customer

matloob hussain

  • Oct 28th, 2005
 

I don;t think the above will work

plese try the following 

Delete from emp a  where a.rowid > ( select min(rowid) from emp b

where a.empno = b.empno group by empno)

Matloob Hussain

  Was this answer useful?  Yes

richardlonghill

  • Jan 20th, 2006
 

Hello,

What you mean eliminate, does it mean to delete the rows or to de-select the duplicate rows..

We can use either distinct or rowid to eliminate duplicate rows

  Was this answer useful?  Yes

Satish Kumar

  • Apr 6th, 2006
 

delete from <table name> a1 where a1.rowid > any (select rowid from <table name> a2 where a1.<col name> = a2.<col name>;

This works....

Regards,                                                                                                              

Satish Kumar

 

  Was this answer useful?  Yes

anonymous

  • Jul 31st, 2006
 

Use distinct keyword.

  Was this answer useful?  Yes

NARENDRA

  • Dec 7th, 2006
 

DELETE FROM EMP E WHERE ROWID NOT IN(SELECT MIN(ROWID) FROM EMP M WHERE E.EMPNO = M.EMPNO);

  Was this answer useful?  Yes

Ramu

  • Jan 5th, 2007
 

there are around 4 ways to eliminate duplicate records upto my knowledge.

the first preferable answer u have to say is :

delete from table_name where rowid not in (select min(rowid) from table_name group by column_name)

if the interviewer asks for another method: try this method.

1. create table_name_b as select distinct * from table_name_a;

2. drop table_name_a;

3. rename table_name_b as table_name_a;

Finished...

and the remaingin methods r confusing where as u will be stopped as soon as u say these 2 types ..

Thanx..

  Was this answer useful?  Yes

jnegimail

  • Nov 2nd, 2009
 

CREATE TABLE duptest
( Id varchar(5),
nonid varchar(5));


INSERT INTO duptest VALUES('1','a');
INSERT INTO duptest VALUES('2','b');


SELECT * FROM duptest


DELETE FROM duptest WHERE rowid NOT IN (SELECT max(rowid) FROM duptest
GROUP BY id)


  Was this answer useful?  Yes

emraan

  • Dec 29th, 2009
 

create table emp_1 as select * from emp

insert into emp_1 select * from emp

select * from emp_1



delete from emp_1 where rowid not in (select min(rowid) from emp_1 group by empno)

  Was this answer useful?  Yes

SujitKr

  • Feb 23rd, 2010
 

DELETE FROM <table name> WHERE rowid NOT IN (SELECT max(rowid) FROM <table name> GROUP BY <column name containing repeated datas>);
AS
table name: t
column name: ename,branch
SQL:  DELETE FROM t WHERE rowid NOT IN (SELECT MAX (rowid) FROM t GROUP BY ename,branch)

Sujit


  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