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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to number rows in select statement

Status
Not open for further replies.

itbnorris

MIS
May 12, 2003
45
US
I am trying to number the rows I retrieve from a select statement but with a catch...

I am grouping my results, and the numbering must restart with each group... ie

Group A
1 Field1 Field2
2 Field1 Field2
Group B
1 Field1 Field2
2 Field1 Field2
3 Field1 Field2

Is there a way to do this in a select statement?

Thanks for your help everyone!
 
Read about ROW_NUMBER function. An example:

SELECT grouping_field
,ROW_NUMBER() OVER (PARTITION BY grouping_field ORDER BY field1, field2) AS ord_no
, field1, field2
FROM my_table

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top