Solved

VB.net SQL Deleting duplicates

Posted on 2014-12-26
3
378 Views
Last Modified: 2014-12-26
Hi

In my VB.net project I pull the data shown below into  a DataGridView using the following SQL statement.
It shows all records with the same Article and  Site combination. How do I delete all duplicates leaving one record
containing the combination

select rtrim([Article])+rtrim([Site]),count(*) As Count_Duplicates from [MARC] group by rtrim([Article])+rtrim([Site]) having count(*)>1

1
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Stefan Hoffmann earned 500 total points
Comment Utility
What SQL Server version?

E.g. using ROW_NUMBER()

 
WITH Ordered AS 
	(
		SELECT 	Article,
			Site,
			ROW_NUMBER() OVER ( PARTITION BY Article, Site ORDER BY anotherColumn ) AS RN
		FROM 	MARC 
	)
	DELETE FROM Ordered
	WHERE	RN > 1;

Open in new window


Caveat: make a backup first.
0
 

Author Comment

by:murbro
Comment Utility
Hi Ste5an. That looks good, I am using SQL 2008
0
 

Author Comment

by:murbro
Comment Utility
thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now