• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

Add column with number of row

I would like to add a column with the number of the row, i.e. the first row is 1, second is 2, third 3 etc.
How can I do that?
0
johnkainn
Asked:
johnkainn
1 Solution
 
JestersGrindCommented:
Use ROW_NUMBER() OVER(YourColumn)

Greg
0
 
Kevin CrossChief Technology OfficerCommented:
I agree with Greg. For some clarity, please see this article:
http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_1555-Analytical-SQL-Where-do-you-rank.html

Please credit Greg for the solution, but you would first need to generate the row number based on some column that identifies your row as first in sort -- syntax is more precisely:
ROW_NUMBER() OVER(ORDER BY your_sort_column) RN

Open in new window


what you may be asking for though is to add an IDENTITY column. If one is not already added, you can do this: ALTER TABLE YourTable ADD ID BIGINT IDENTITY(1,1);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now