Solved

Need to mark duplicate rows

Posted on 2010-08-12
2
416 Views
Last Modified: 2012-05-10
I need to mark rows in a table that have an ID in the file more than once.  If it is in 3 times then mark it 1,2,3 twice 1,2 once just a 1. can't figure out how to break the count on the id number by grouping using the row_number function any ideas?  mahalo Mark  

0
Comment
Question by:Wonderwall
2 Comments
 
LVL 16

Expert Comment

by:vdr1620
ID: 33423543
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33423630
As a select query

select rn=row_number() over (partition by id order by id), *
from tbl

where rn gives you the "mark" you are after

or as an update if you have a column to hold this value

;with tmp as (
select rn=row_number() over (partition by id order by id), *
from tbl
)
update tmp set targetcol = rn
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OPENDATASOURCE 8 36
SQL Server; storing data in offline mode. 10 67
create index to c1, c2 and c3 9 67
sql query help 7 96
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

22 Experts available now in Live!

Get 1:1 Help Now