adspace


Delete duplicate rows from a table without primary key by
using a single query
Table Employee
empname salary
A 200
B 300
A 200
C 400
D 500
D 500

Output should be

A 200
B 300
C 400
D 500

Answer Posted / shankaranarayanan v

while exists(select count(*) from employee group by empname having count(*)>1)
begin

delete top(1) from employee where empname in
(
select min(empname) as deletedname
from employee
group by empname
having count(*)>1
)

end

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does view occupy space?

1019


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

1071


How do I find query history in sql server?

1024


What are the different types of subquery?

1235


What is self contained sub query?

1140


What is an indexed view?

1022


do you know how to configure db2 side of the application? : Sql server database administration

1124


what is the difference between openrowset and openquery?

1194


What is in place upgrade in sql server?

1126


Explain “row_number()” in sql server with an example?

1079


What is sql or structured query language?

1227


what is spatial nonclustered index

1058


What are the source of constraints?

1009


What is normalization and what are the advantages of it?

1055


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?

1213