Solved

SQL Server DeDupe Table

Posted on 2016-08-22
3
41 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
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 65

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2016 SQL Licensing 7 41
sql select record as one long string 21 24
TSQL query to generate xml 4 36
Need help with a Stored Proc on Sql Server 2012 4 11
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

831 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