How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?
Answers were Sorted based on User's Feedback
Answer / mon
DELETE FROM MyTable
LEFT OUTER JOIN (
SELECT MIN(RowId) as RowId, Col1, Col2, Col3
FROM MyTable
GROUP BY Col1, Col2, Col3
) as KeepRows ON
MyTable.RowId = KeepRows.RowId
WHERE
KeepRows.RowId IS NULL
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / arun kumar k s
drop table #TEMP select distinct * into #TEMP from
TABLE_NAME delete from TABLE_NAME insert into TABLE_NAME
select * from #TEMP
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / gaurav jain
begin
select distinct * into #one from four where id in (select
id from four group by id
having count(*)>1)
delete from four where id in (select id from four group by
id having count(*)>1)
insert into four select * from #one
end
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / anoop rajan
Tbale emp had some duplicate entries and i wanted to retain
the first of all duplicates, the others could be deleted as
follows . Please give your comments if this is the most
optimum way :
delete from emp where rowid in
(select rowid from emp o where rowid !=
(select min(rowid) from emp i where i.empno=o.empno));
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / pawan k. dubey
delete from employee
where Emp_id not in (select min(Emp_id) from employee
group by Emp_Name)
| Is This Answer Correct ? | 2 Yes | 12 No |
What is live lock and deadlock? what is Lock escalation?
what is differece between union and union all
How to assign null values to variables or columns?
What is a trigger? Why we need it?
What is difference between createstatement and preparedstatement?
What is a cursor in SQL Server 2000 and their types?
How to loop through the result set with @@fetch_status?
How to sort query output in descending order in ms sql server?
What is an inner join?
List down some advantages of sql stored procedure?
Is there any difference between primary key and unique with the not null condition?
What is the difference between sdf and mdf?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)