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

What are the grouping functions?

532


Tell about MOM Tool(Microsoft Operator Manager)?

1413


How to view existing indexes on an given table using sp_help?

597


What are the different types of join?

573


What is the contrast between sql and mysql?

594






What is transaction server auto commit?

579


Do you know what are acid properties of transaction?

526


when you create a database how is it stored? : Sql server database administration

499


What is the meaning of resultset type_scroll_insensitive?

565


What gets stored inside msdb database?

769


How to list all triggers in the database with sys.triggers in ms sql server?

539


What is a matrix in ssrs?

101


Explain transaction server auto commit?

537


How to enforce security in sql server? : sql server security

624


Explain how to send email from sql database?

568