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
What is DCL?
How will you go about resolving deadlocks?
What is outer join in sql server joins?
How to create a store procedure with encryption?
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?
How to count rows with the count(*) function in ms sql server?
Difference between uniqe index and uniqe constraint?
If we delete pack Spec what will be the status of pack Body ?
What are the disadvantages of using the stored procedures?
How to write a query with an inner join in ms sql server?
What is database replication? What are the different types of replication you can set up in sql server?
can SSRS reports Cache results?
How to Check if table exists in sql server?
What is instead of trigger sql server?
How to create percentile function?