---
title: "How to find the Nth maximum and minimum value in sqlserver."  
description: "How to find the Nth maximum and minimum value in sqlserver."  
author: "Anonymous User"  
published: 2016-01-13  
updated: 2016-01-13  
canonical: https://www.mindstick.com/forum/33867/how-to-find-the-nth-maximum-and-minimum-value-in-sqlserver  
category: "database"  
tags: ["sql server", "sql", "sql server 2008", "sql server 2012"]  
reading_time: 1 minute  

---

# How to find the Nth maximum and minimum value in sqlserver.

I want to To find the Nth maximum and minimum [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) in sqlserver.

## Replies

### Reply by Anonymous User

```
DECLARE @table TABLE(ID integer,AMOUNT integer)INSERT INTO @table values(1, 5000)INSERT INTO @table values(2, 200)INSERT INTO @table values(3, 4500)INSERT INTO @table values(4, 3000)INSERT INTO @table values(5, 3200)INSERT INTO @table values(6, 3100)INSERT INTO @table values(7, 150)
SELECT ID, AMOUNTFROM(SELECT ID, AMOUNT, Row_Number() OVER(ORDER BY AMOUNT DESC) AS highestFROM @table) as xWHERE highest = 1SELECT id, AMOUNT
FROM(
SELECT id, amount, Row_Number() OVER(ORDER BY AMOUNT ASC) AS lowest
FROM @table
) as x
WHERE lowest =1
```

```

```


---

Original Source: https://www.mindstick.com/forum/33867/how-to-find-the-nth-maximum-and-minimum-value-in-sqlserver

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
