Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do I flag duplicates?

Author  Topic 

MMMY
Starting Member

14 Posts

Posted - 2012-04-25 : 09:09:37
Table Example:


ID NAME FLAG
1 Bill null
2 Bill null
3 Bill null
4 Bob null
5 Henry null
6 Henry null


I want to keep the flag empty for one record and mark the rest as duplicates so the output would be:


ID NAME FLAG
1 Bill null
2 Bill D
3 Bill D
4 Bob null
5 Henry null
6 Henry D



How can I go about doing this? Thank you very much!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-25 : 09:13:50
update dt
set FLAG = 'D'
from
(select row_number() over (partition by NAME order by ID) as rnum,* from YourTable)dt
where rnum > 1


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

MMMY
Starting Member

14 Posts

Posted - 2012-04-25 : 09:40:32
Thank you very much!
Go to Top of Page

Subarcticguy
Starting Member

2 Posts

Posted - 2013-11-18 : 18:40:47
I am trying to do something similar in an access database, however I have about 33 fields in the table for which I want to include about 25 of the fields when checking for duplicates.

To further explain the table (called CollarData) has the first 25 fields which are imported from various text files, the other fields are more metadata fields such as importDate, importSource, and Duplicate Flag fields. I only want to check the first 25 fields when checking for duplicates. I want to add the "DUP" flag to a field called QAQC in the same table.

I have been trying using various techniques for weeks but I can't seem to get the syntax right. Any help would be greatly appreciated.


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-19 : 01:26:09
quote:
Originally posted by Subarcticguy

I am trying to do something similar in an access database, however I have about 33 fields in the table for which I want to include about 25 of the fields when checking for duplicates.

To further explain the table (called CollarData) has the first 25 fields which are imported from various text files, the other fields are more metadata fields such as importDate, importSource, and Duplicate Flag fields. I only want to check the first 25 fields when checking for duplicates. I want to add the "DUP" flag to a field called QAQC in the same table.

I have been trying using various techniques for weeks but I can't seem to get the syntax right. Any help would be greatly appreciated.





You've to post this in Access forum if you're looking at Access query

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -