Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numbering duplicates

Status
Not open for further replies.

markgargan

Programmer
Apr 4, 2005
25
IE
Hi folks,

Say I have the following table

id | name
---------
1 Michael
2 James
3 John
4 James
5 Michael
6 James

Is there any select function I can perform that
could print out the values of the id, name column and a number representing the ith time this name appears
in the column? i.e. the result set would look like this.

id | name | ith
---------------
1 Michael 1
2 James 1
3 John 1
4 James 2
5 Michael 2
6 James 3


Sorry for the poor explanation I can't think of the proper term for this ith column? Version? Sequence number? Appearance count?

Thanks,
Mark.
 
Mark,

It is probably not meant for the purpose, but test this:

Code:
Select 
rank() over (partition by name order by id asc) as ith
from table
order by name



Ties Blom
Information analyst
 
Hi Ties,

Well that is perfect Ties. Thanks a million!!
Would you know of anywhere were I could get a list and a few
samples of similar functions? I was attempting it with a subselect and the ROW_NUMBER() function to no avail.

Thanks again,
Mark.
 
*Blub* *blub* it's soooo pretty... SOOOO pretty.
I promised myself I wouldn't cry..

Thanks a thousand times Ties,
Mark.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top