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 / shankaranarayanan v

while exists(select count(*) from employee group by empname having count(*)>1)
begin

delete top(1) from employee where empname in
(
select min(empname) as deletedname
from employee
group by empname
having count(*)>1
)

end

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is sql collation?

1137


How to use "begin ... End" statement structures in ms sql server?

957


What are the types of dml?

930


Explain system scalar functions?

952


What sql server means?

909


Is it possible to call a stored procedure within a stored procedure?

914


How to see existing views in ms sql server?

987


What does Master database contains?

1083


What is the difference RDBMS and Graph Database?

1004


What is an etl file?

900


What are the steps to process a single select statement?

887


Do you know what are pages and extents? : SQL Server Architecture

941


Can we use where and having clause together?

978


Explain the different index configurations a table can have?

885


What do you understand by recursive stored procedures?

938