?
Solved

VB.net SQL Deleting duplicates

Posted on 2014-12-26
3
Medium Priority
?
424 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 2000 total points
ID: 40518393
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:Murray Brown
ID: 40518452
Hi Ste5an. That looks good, I am using SQL 2008
0
 

Author Comment

by:Murray Brown
ID: 40518475
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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
Suggested Courses

801 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