How To delete duplicate record from a particular table?

Answer Posted / kala suresh

--BY USING A TEMP TABLE TO DELETE DUPLICATE ROWS OF A TABLE
WITH OUT A PRIMARY KEY COLUMN OR AN IDENTITY COLUMN

SELECT Name, age, ROW_NUMBER() OVER(ORDER BY age) AS
'RowNumber' into #temp1 FROM RowNumber

delete from #temp1 where rownumber not in(select
max(rownumber) from #temp1 group by name,age)

delete from rownumber

select * from #temp1 into rownumber

drop table #temp1


--BY USING AN IDENTITY COLUMN TO DELETE DUPLICATE ROWS OF A
--TABLE WITH OUT A PRIMARY KEY COLUMN

delete from rownumber where id not in(select min(id) from
rownumber group by name,age)
select * from rownumber

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is DCL?

599


How will you go about resolving deadlocks?

565


What is outer join in sql server joins?

604


How to create a store procedure with encryption?

527


What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting are possible?

569






How to count rows with the count(*) function in ms sql server?

547


Difference between uniqe index and uniqe constraint?

560


If we delete pack Spec what will be the status of pack Body ?

975


What are the disadvantages of using the stored procedures?

555


How to write a query with an inner join in ms sql server?

554


What is database replication? What are the different types of replication you can set up in sql server?

516


can SSRS reports Cache results?

113


How to Check if table exists in sql server?

628


What is instead of trigger sql server?

506


How to create percentile function?

110