Important alert: (current site time 7/15/2013 7:05:23 PM EDT)
 

article

Delete Duplicated Rows in one query, simple and easy

Email
Submitted on: 4/4/2005 6:02:54 PM
By: mid.net 
Level: Intermediate
User Rating: By 5 Users
Compatibility: SQL Server 2000, SQL Server 7.0, SQL Server 6.5 and earlier, Other
Views: 12563
(About the author)
 
     Delete duplicated Rows width have an Identity (unique) Column

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

Table Original

Id Descript
1 aa
2 aa
3 bb
4 cc
5 dd
6 dd
7 ee

I want to delete all Duplicated by 'Descrip'

Delete from mitable where id Not In (Select top 1 id from mitable as MR1 where MR1.descrip=mitable.descrip)

Id

Descript
1 aa
3 bb
4 cc
5 dd
7 ee

All Dupplicated Data Removed enjoy that


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/5/2005 4:30:10 AMdsoftnet

How you will be identifying which row wil get deleted, assum you have one table containing name as
(If this comment was disrespectful, please report it.)

 
4/5/2005 7:27:57 AMmid.net

the "delete" query remove all duplicated item without any other information than the table which contains the duplicated rows, try the query and you see which I tell you
(If this comment was disrespectful, please report it.)

 
7/4/2005 5:15:57 AM

it is very good
(If this comment was disrespectful, please report it.)

 
1/30/2007 12:40:01 AMkaja

display the first 5 maximum salary for each department
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.