Write a query to delete duplicate records in SQL SERVER

Answer Posted / sunil

CREATE TABLE [dbo].[DupTable](
[Name] [nchar](10) NOT NULL,
[Age] [int] NOT NULL
) ON [PRIMARY]

-- Insert the duplicate data into the table...



Select * from DupTable
go

with Emp AS
(
Select Name,Age, ROW_NUMBER() over (order by Name) as
RowNumber FROM DupTable
)
Delete t1 From Emp as T1, Emp as T2
where T1.Name = T2.Name AND T1.Age= T2.Age and T1.RowNumber
> T2.RowNumber
go

Select * from DupTable
go

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is Sqlpaging in SqlServer 2005 ?

664


What is filter index?

519


What is 4nf in normalization form?

573


What is a domain constraint give an example?

567


Does a specific recovery model need to be used for a replicated database? : sql server replication

536






To which devices can a backup be created and where should these devices be located? : sql server management studio

571


What is the preferred way to create a clustered and non-clustered index? Which index should you create first the clustered or non-clustered?

479


Can you insert NULL in unique column?

635


What are the ways available in sql server to execute sql statements?

574


What is SQL Azure Fabric?

92


How can you find out how many rows returned in a cursor?

554


What are the rendering extensions of ssrs?

105


Can one drop a column from a table?

552


How to create new tables with "select ... Into" statements in ms sql server?

518


Tell me about builtinadministrator?

564