Friday, May 2, 2008

Deleting Duplicate Records in the Table

Table Name : Test2
Fields : empid,empname

Query to Delete the Duplicate values and keeping one value in the table.

set rowcount 1
select 1
while @@rowcount > 0
delete test2
where 1 < (select count(*) from test2 a2 where test2.empid = a2.empid)
set rowcount 0

No comments: