Solved

SQL Server DeDupe Table

Posted on 2016-08-22
3
28 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
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
;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
Comment Utility
Thanks
0
 
LVL 65

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

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

9 Experts available now in Live!

Get 1:1 Help Now