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
How will you monitor replication latency in transactional replication? : sql server replication
What is sub-query in sql server?
What is replace and stuff function in sql server?
Explain the phases a transaction has to undergo?
What is role playing dimension with two examples? : sql server analysis services, ssas
What are the built in functions in sql server?
Difference between group by clause and having clause in SQL?
Does group by sort data?
What is public role in sql server?
What is the default value of an integer data type in sql server 2005?
Please differentiate between a local and a global temporary table?
how can you find out if the current user is a member of the specified microsoft® windows nt® group or microsoft sql server™ role? : Sql server administration
What guidelines should be followed to help minimize deadlocks?
Explain about thread and memory management process of SQL?
Why use triggers?