By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,361 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,361 IT Pros & Developers. It's quick & easy.

Delete Duplicate Columns

P: 95
Create table info(comp_id int identity(101,1),comp_name varchar(50))
insert into info values('Progressive Ltd.')
insert into info values('Progressive Ltd.')
insert into info values('EliResearch')
insert into info values('Patni')
insert into info values('Accenture')
insert into info values('Accenture')
select * from info

I want to delete those entries from the table that have duplicate company names.
I m not getting it,Plz reply.
Apr 15 '08 #1
Share this Question
Share on Google+
2 Replies


deepuv04
Expert 100+
P: 227
Create table info(comp_id int identity(101,1),comp_name varchar(50))
insert into info values('Progressive Ltd.')
insert into info values('Progressive Ltd.')
insert into info values('EliResearch')
insert into info values('Patni')
insert into info values('Accenture')
insert into info values('Accenture')
select * from info

I want to delete those entries from the table that have duplicate company names.
I m not getting it,Plz reply.
hi
try the following query

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM [info] 
  2. WHERE [comp_name] IN
  3. (SELECT [comp_name] FROM [info] 
  4. GROUP BY [comp_name] HAVING COUNT([comp_name]) > 1)
  5.  
Apr 15 '08 #2

P: 95
Thanks,
it worked.
Apr 15 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.