Solved

SQL Server DeDupe Table

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculated columns 13 60
xpath sql query 2008 8 41
SQL FUll Text Not returning any results 2 15
TSQL previous 5 21
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

947 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

19 Experts available now in Live!

Get 1:1 Help Now