how to delete duplicate rows from table

Answer Posted / anand

TABLENAME: testanand
DATA:
id vanme emailid age
-- ------ ---------- ------
1 Anand anand.kv@abc.com 29
2 Anand anand.kv@abc.com 28
3 Rajesh rajesh@abc.com 30
4 Rajesh rajesh@abc.com 31
5 Vinit vinit@abc.com 21
6 Vinit vinit@abc.com 25

DELETE FROM testanand WHERE id Not IN
(SELECT min(id) FROM testanand GROUP BY vname)

RESULTS:

id vanme emailid age
-- ------ ---------- ------
1 Anand anand.kv@abc.com 29
3 Rajesh rajesh@abc.com 30
5 Vinit vinit@abc.com 21

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of grouping data in a report?

536


What is difference between foreign key and unique key?

546


What is the new security features added in sql server 2014? : sql server security

563


What is rs.exe utility?

118


how would you store your query in an SSRS report or a Database server?

116






How to list all user names in a database?

586


what are the different stages of Report Processing?

97


What authentication modes does sql server support?

594


what are triggers? : Sql server database administration

495


Explain about integration services of Microsoft SQL server?

580


Relational calculus is what type of language?

573


What is purpose of normalization?

524


How to use subqueries in the from clause in ms sql server?

563


How to delete multiple rows with one delete statement in ms sql server?

513


How do I start sql server 2017?

528