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

Which tcp/ip port does the sql server run on? How can it be changed?

1099


What is sql profiler. What are the default templates with it? : sql server database administration

1104


We need to perform what steps in the following order to work with a cursor?

1272


Create and insert into temp table in sql server?

1079


What is user-defined functions? What are the types of user-defined functions that can be created?

1076


How to resolve the orphan use problem? : sql server security

1069


What is the difference between drop table and truncate table?

972


What is the purpose of forms?

1003


How to apply cascading referential integrity in place of triggers?

1087


What are different types of raid levels?

1234


What is mscorsvw.exe - process - microsoft .net framework ngen?

999


how to restart sql server in single user mode? How to start sql server in minimal configuration mode? : Sql server database administration

958


How to send email from database?

1069


What is an etl file?

1004


Explain what are magic tables in sql server?

1046