Sunday, November 2, 2008

Query to find duplicate record in SQL server table & store into table

1) Simple query to find duplicate records in SQL server

select a,count(1)
from #temp
group by a
having count(1) > 1
order by count(1) desc

2) Dump the duplicate records into SQL table
create table #temp (a varchar(15),b varchar(15),c int)
insert into #temp
select emp_no,emp_name,count(1)
from employee
group by emp_no,emp_name
having count(1) > 1



drop table #temp

No comments: