---
title: "How to use ROW_NUMBER  in sqlserver"  
description: "How to use ROW_NUMBER  in sqlserver"  
author: "Anonymous User"  
published: 2015-11-26  
updated: 2015-11-26  
canonical: https://www.mindstick.com/forum/33643/how-to-use-row_number-in-sqlserver  
category: "database"  
tags: ["sql server", "sql", "sql server 2008"]  
reading_time: 1 minute  

---

# How to use ROW_NUMBER  in sqlserver

I want to use ROW_NUMBER in [sql server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) Please help me.

## Replies

### Reply by Anonymous User

ROW_NUMBER is a function built-in to [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) that will return a row number for each record in your result set. You can further change resulting row number to reset the row number based on some value in the result set.

PARTITION BY – If you supply this parameter, then the row number will reset based on the value changing in the columns supplied. This is kinda like using a GROUP BY.\
ORDER BY – This is the specified order of the row number that you would like. If you wanted the order of the row number to increment by an employee name (alphabetically), you do that here.

```
select ROW_NUMBER() over (ORDER BY emp_name) AS RowNumber,Emp_ID,Emp_Name,Emp_Sal from Employee
```

![How to use ROW_NUMBER  in sqlserver](https://www.mindstick.com/mindstickforums/42fe1397-b87d-4812-a49b-059ac5bd9afa/images/c6a12de6-c349-4419-8a7f-1140db6580c5.png)

```
select ROW_NUMBER() over (PARTITION BY emp_sal ORDER BY emp_name) AS RowNumber,Emp_ID,Emp_Name,Emp_Sal from Employee
```

![How to use ROW_NUMBER  in sqlserver](https://www.mindstick.com/mindstickforums/42fe1397-b87d-4812-a49b-059ac5bd9afa/images/2b2b5aab-854e-4876-bd58-9e7b018e7230.png)


---

Original Source: https://www.mindstick.com/forum/33643/how-to-use-row_number-in-sqlserver

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
