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 / swati tripathi

declare myCursor cursor for
select empid
from employee
group by empid
having count(*) > 1

declare @EmpId int


OPEN myCursor;
FETCH NEXT FROM myCursor INTO @EmpId
WHILE @@FETCH_STATUS = 0
BEGIN

delete top(select count(*)-1 from employee where
empid=@EmpId) from employee where empid=@EmpId

FETCH NEXT FROM myCursor INTO @EmpId
END
close myCursor

deallocate myCursor

Is This Answer Correct ?    11 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between dataadapter and datareader?

997


what is the primary use of the model database? : Sql server administration

1044


What are the types of processing and explain each? : sql server analysis services, ssas

1146


Can group functions be used in the order by clause in ms sql server?

1011


How to change the data type of an existing column with "alter table" statements in ms sql server?

980


How many primary keys are possible in a table?

919


Explain about system stored procedure?

1030


What is tcl in sql server?

1117


What are different types of roles provided by ssrs?

150


What are the five major components of a dbms?

927


what changed between the previous version of sql server and the current version? : Sql server database administration

999


How do I delete a sql server database?

1039


Can you explain various data region available in ssrs with their use?

969


Tell me about normalization in DBMS.

993


What is candidate key with example?

975