Solved

Need to mark duplicate rows

Posted on 2010-08-12
2
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Backup & Restore 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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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