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 / samba shiva reddy . m

delclare @temp(empname varchar(50),sal int)
select * into @temp
FROM employee
GROUP BY empname, salary
HAVING count(*) > 1
delete from employee
select * into employee from @temp as temp

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between DATETIME2 and DATETIME?

618


How will you know when statistics on a table are obsolete?

597


What are the reporting services components?

92


Where the sql logs gets stored? : sql server database administration

520


Can a stored procedure call itself or recursive stored procedure? How much level sp nesting is possible?

605






How to modify an existing stored procedure in ms sql server?

521


Define Joins?

603


how do you determine the Load performance of any query in sql server {example how do u determine performance of a select stmnt which returns Dynamically many no of records ... some times 100,1000,10000 etc., }

1837


What is a hint?

576


What is "scheduled jobs" or "scheduled tasks"?

551


Is it possible in sql table to have more than one foreign key?

606


Define constraints and give an example of their use?

557


What is clr ddl trigger?

543


Do you know what is a with(nolock)?

594


How would you use user_constraints table in DB?

582