Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / sunil

set rowcount 1 -- set row count 1

delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1

while @@rowcount > 0
begin
delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1
end
set rowcount 0

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain acid?

1086


How to stop a loop early with break statements in ms sql server?

1020


What are transactions in sql?

1066


What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?

137


Explain the use of containers in ssis and also their types?

970


what are the critical issues you have resloved in your company

1964


What is subquery in sql?

1072


what are the steps you will take, if you are tasked with securing an sql server? : Sql server database administration

1043


What is an index. What are the types?

1092


What does ss stand for sexually?

1089


what are different types of raid configurations? : Sql server database administration

1065


How to get the definition of a user defined function back?

1044


List some of the rules that apply to creating and using a ‘view’

888


Do you know what is user defined datatypes and when you should go for them?

968


What is dbcc updateusage?

1210