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

How to assign null values to variables or columns?

915


Why should you use or avoid select * statements?

969


what types of replication are supported in sql server? : Sql server database administration

959


What does it mean to normalize data?

896


How to create a simple stored procedure in ms sql server?

979


What is buffer cash and log cache in sql server?

1056


What are ddl triggers and types of ddl trigger?

978


How to create a user name in a database?

996


What is local temp table?

897


Mention the differences between local and global temporary tables.

955


Explain the difference between functions and stored procedures in sql server?

921


What are sql server procedures?

931


where the connection string store in the database

2019


Do you know how to implement service broker?

887


How adventureworkslt tables are related?

881