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 are the steps you will take to improve performance of a poor performing query? : Sql server database administration
What are the different authentication modes in sql server?
How efficient you are in oracle and SQL server?
Do you know concepts and capabilities of sql server?
there is a trigger defined for insert operations on a table, in an oltp system. The trigger is written to instantiate a com object and pass the newly inserted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better? : Sql server database administration
What's new in sql management studio for sql server? : sql server management studio
Ways to improve the performance of a SQL Azure Database?
How to stop a loop early with break statements in ms sql server?
What is Extended user-defined?
How to check if a table is being used in sql server?
How to write an inner join with the where clause in ms sql server?
How to find the list of fixed hard drive and free space on server?
How to choose all records from the table?
Explain about local stored procedure?
What are the disadvantages of indexes?