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

Do you know what is difference between index seek vs. Index scan?

895


Why does sql studio use a single registered database repository? : sql server management studio

948


Can the “if update (colname)” statement be used in a delete trigger?

941


What is normalization? Explain different forms of normalization?

1069


Explain magic tables in sql server?

978


What are the types of subquery?

979


Is it possible in sql table to have more than one foreign key?

975


IF more than one Site is accessing the same Database server and I want to move the DB with Minimum down time? How will you do

1755


Explain the stored procedure?

985


What are the different types of indexes?

1040


What is the syntax to execute the sys.dm_db_missing_index_details?

964


Explain Capacity planning to create a database? and how to monitor it?

4140


Explain trigger and trigger types?

905


Do you know what is a linked server in sql server?

960


Explain cursor as data base object?

970