Save up to $499! Grab all Python courses for $49 or all online courses we’ve ever launched for only $169. Only Feb 11-16. Happy Valentine's!
Ranking functions
Selecting n-th row


As you can see, ROW_NUMBER() gives a unique rank to each row. Even those rows which share the same EditorRating value got different ranks. Notice that the ranks are expressed as consecutive numbers.

The only problem with this is with the order of these consecutive numbers. How does SQL Server determine the ranking order when all the ranking values are the same? The answer is... it doesn't, really. The order is nondeterministic. When you execute ROW_NUMBER(), you never really know what the output will be.

Now, how about a practice exercise?


Show the name, release date and rank based on the release date of each game. Use ROW_NUMBER() and name the last column RowNumber.

Stuck? Here's a hint!

Use the previous example to help you:

  ROW_NUMBER() OVER(ORDER BY EditorRating ASC) AS RowNumber
FROM Game;