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
What is Sqlpaging in SqlServer 2005 ?
What is filter index?
What is 4nf in normalization form?
What is a domain constraint give an example?
Does a specific recovery model need to be used for a replicated database? : sql server replication
To which devices can a backup be created and where should these devices be located? : sql server management studio
What is the preferred way to create a clustered and non-clustered index? Which index should you create first the clustered or non-clustered?
Can you insert NULL in unique column?
What are the ways available in sql server to execute sql statements?
What is SQL Azure Fabric?
How can you find out how many rows returned in a cursor?
What are the rendering extensions of ssrs?
Can one drop a column from a table?
How to create new tables with "select ... Into" statements in ms sql server?
Tell me about builtinadministrator?