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 triggers and its types?

547


What is the full form of ddl?

511


Where do we use trace frag?

574


Explain about the command-line tool SQLCMD?

557


How can we get count of the number of records in a table?

549






What are the five major components of a dbms?

514


How can you hide the sql server instances?

519


Where are sql server usernames and passwords stored in the sql server?

613


How can we delete a table in sql server?

556


What is difference between index and primary key?

590


Do you know data definition language, data control language and data manipulation language?

630


What is data set in report?

97


What is dynamic cursor in SQL SERVER?

565


Explain cross join or cartesian product in sql?

546


Where actually sql azure database is hosted?

149