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 the contrast between sql and mysql?
How to create a view with data from multiple tables?
What is single-user mode?
Write an sql query to find first weekday of the month?
What is query and its types?
Explain linked server in sql?
Define left outer join in sql server joins?
What is the difference between count and distinct count?
What is the difference between char, varchar and nvarchar?
What are SSL and TSL protocols?
What is the use of commit?
What are the differences between web role and worker role?
Explain primary key?
Explain the difference between clustered and non-clustered index?
Why truncate is ddl?