How do I use ROW_NUMBER()?

I want to use the ROW_NUMBER() to get…

  1. To get the max(ROW_NUMBER()) –> Or i guess this would also be the count of all rows

I tried doing:

SELECT max(ROW_NUMBER() OVER(ORDER BY UserId)) FROM Users

but it didn’t seem to work…

  1. To get ROW_NUMBER() using a given piece of information, ie. if I have a name and I want to know what row the name came from.

I assume it would be something similar to what I tried for #1

SELECT ROW_NUMBER() OVER(ORDER BY UserId) From Users WHERE UserName="Joe"

but this didn’t work either…

Any Ideas?

13 Answers
13

Leave a Comment