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 disadvantages of indexes?
How we can compare two database data?
Can we use where and having clause together?
What is the usage of sign function?
Explain the difference between function and stored procedure?
Who developed sql server?
Can we call future method from queueable?
What is transact-sql language?
How do I completely remove sql server instance?
Which event (check constraints, foreign key, rule, trigger, primary key check) will be performed last for an integrity check?
What is row_number()?
How many types of triggers in sql server?
Explain can SSRS reports Cache results?
Which are the olap features?
Explain nested stored procedure. Syntax and an example for create nested stored procedure?