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

What are translations and its use? : sql server analysis services, ssas

1036


What are the new data types are introduced in sql 2000?

899


How to create a user to access a database in ms sql server using "create user" statements?

948


How to drop an existing user defined function in ms sql server?

1023


Which sql server is best?

990


How to compose an inquiry to demonstrate the points of interest of an understudy from students table whose name begins with k?

1089


What is reference section?

997


Can we perform backup restore operation on tempdb?

1004


You want to generate a report that is formatted as a chart. Can you use the report wizard to create such a report?

121


What is the difference between createstatement and preparedstatement?

936


What is difference between count (*) and count column?

896


What are the main sources of data?

1090


What is change data capture (cdc) feature?

1058


Why truncate is ddl?

1084


What is data source view or dsv? : sql server analysis services, ssas

1000