?
Solved

SQL Server DeDupe Table

Posted on 2016-08-22
3
Medium Priority
?
55 Views
Last Modified: 2016-08-22
The SQL Statement below returns data that for absolute sure...
Any row number > 1 is a dup record

What is the most efficient way to delet those records from the table?
There are no foreign keys etc...

SELECT      SalesSiteToChannelID,
            ChannelID ,
            SalesSiteID,
            ROW_NUMBER() OVER(PARTITION BY SalesSiteID ORDER BY ChannelID, SalesSiteID) AS RowNumber
FROM      ewSalesSitesToChannels
0
Comment
Question by:lrbrister
[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 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 41765806
;with cte as (
   --- Your table here
   SELECT SalesSiteToChannelID,
      ChannelID ,
      SalesSiteID,
      ROW_NUMBER() OVER(PARTITION BY SalesSiteID ORDER BY ChannelID, SalesSiteID) AS RowNumber
   FROM ewSalesSitesToChannels) 
DELETE from cte WHERE row_number > 1

Open in new window


Check out SQL Server Delete Duplicate Rows for a demo.
0
 

Author Closing Comment

by:lrbrister
ID: 41765807
Thanks
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41765966
Thanks for the accept, good luck with your project.  -JIm
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

752 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