ROW_NUMBER (Transact-SQL)

The ROW_NUMBER() function returns the number of a row within a result set starting with 1 for the first row. The ROW_NUMBER() function does not execute until after a WHERE clause is used to select the subset of data.

The following example returns the row number for each contact in AdventureWorks based on the LastName and FirstName:

USE 
 
AdventureWorksGO
 
 
SELECT

 
ROW_NUMBER() OVER (ORDER BY LastName, FirstName),
 
 
 
 
 
 
 
 
 

 

ContactID
, FirstName, LastName
 
 
 
 
 
 
 
 
 

 

FROM

 
Person.Contact
 
 
 
 
 
 
 
 
 

 

Update me when site is updated

Leave a Reply

You must be logged in to post a comment.