adspace
I have a table EMP in which the values will be like this
EmpId Ename Sal DeptId
11 Ram 10000 10
11 Ram 10000 10
22 Raj 20000 20
22 Raj 20000 20
33 Anil 15000 30
33 Anil 15000 30
I want to delete only duplicate Rows. After Delete I want
the output like this
EmpId Ename Sal DeptId
11 Ram 10000 10
22 Raj 20000 20
33 Anil 15000 30
Answer Posted / aashish lad
-- Here Temp1 is Temporary Table So it will take All records
-- From Mytable With RowNumbar column
-- We can Delete the Record from
SELECT ROW_NUMBER() OVER(PARTITION BY empid ORDER BY empid)
AS RowNumber, * into #temp1 FROM mytable
DELETE FROM #temp1 WHERE RowNumber> 1
INSERT INTO mytable
SELECT * FROM #temp
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?
How to convert numeric expression data types using the cast() function?
How to remove duplicate rows from table except one?
What are the properties of the transaction?
Equi join and non equi join is possible with sql server?
If any stored procedure is encrypted, then can we see its definition in activity monitor?
what is spatial nonclustered index
What are the different SQL Server Versions you have worked on?
Why we use the openxml clause?
List out the different types of locks available in sql server?
What is clustered index
What is a coalesce function?
List the ways in which dynamic sql can be executed?
What are different types of constraints?
What is self contained sub query?