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


Please Help Members By Posting Answers For Below Questions

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?

1212


How to convert numeric expression data types using the cast() function?

1147


How to remove duplicate rows from table except one?

1087


What are the properties of the transaction?

1072


Equi join and non equi join is possible with sql server?

1134


If any stored procedure is encrypted, then can we see its definition in activity monitor?

1070


what is spatial nonclustered index

1057


What are the different SQL Server Versions you have worked on?

1078


Why we use the openxml clause?

1078


List out the different types of locks available in sql server?

1049


What is clustered index

1085


What is a coalesce function?

1282


List the ways in which dynamic sql can be executed?

1085


What are different types of constraints?

1000


What is self contained sub query?

1139