Solved

Update sql statement for DELETING DUPS in 2 fields

Posted on 2011-09-26
2
201 Views
Last Modified: 2012-05-12
sql server 2008
What I need:
To delete duplicates based on 2 fields.

 


1 table:
In my Table...
field 1  =  "Material_no"  is a PK field(Yes dups ok).
field2 =   "alt_acc_material_no" (pk field no dups)
Right now I'm using cte to delete dups from a table with 1 primary field...


code for one primary field:
with CTE as (
      select *, row_number() over (partition by material_no order by material_no) rn
      from crs_staging
)
delete from CTE where rn > 1

1A123       4RRT5     < OK
1A123       55T56     <  OK
1SS23       1WW25  
5TT56        666T6      
5TT56        666T6            <----- DELETE



Thanks
fordraiders


0
Comment
Question by:fordraiders
2 Comments
 
LVL 8

Accepted Solution

by:
venk_r earned 500 total points
Comment Utility
try this
with CTE as (
      select *, row_number() over (partition by material_no,alt_acc_material_no order by material_no,alt_acc_material_no) rn
      from crs_staging
)
delete from CTE where rn != 1

0
 
LVL 3

Author Closing Comment

by:fordraiders
Comment Utility
Thanjks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

17 Experts available now in Live!

Get 1:1 Help Now