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

How can we rewrite sub-queries into simple select statements or with joins?

941


How do I manually uninstall an instance of sql server 2016?

980


How to specify the collation for a character data type in ms sql server?

983


What are the built in functions in sql server?

934


What is difference between aggregate and analytic function?

888


How do I delete a sql server database?

1001


What is use of attributehierarchyenabled? : sql server analysis services, ssas

1181


Explain how to send email from sql database?

991


How do I find the size of a sql server database?

894


What is Cross Join and in which scenario do we use Cross Join?

984


What are the features of Embedded SQL

1093


your distribution database is full what will u do

2140


in a table is b in column k (manikanta,sivananda,muralidhar) i want result like (mnikanta,sivnanda,murlidhar) please slove it

1470


Do you know how to send email from database?

942


What is the difference between join and inner join?

966