## 4 replies

Last post Jan 27, 2016 08:08 AM by sandeepmittal11

• Capricon Use...

Member

239 Points

1070 Posts

### lowest and highest salaries display

Jan 25, 2016 03:50 AM|Capricon User|LINK

i try to get top 5 salary and second highest salary from employees table but it shows me also lowest salaries

check this picture ssalry column

and this is the output

this is the queries which i try

SELECT MAX(Salary) FROM Employees
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employees )

select top 5 salary from Employees;

• anuj_koundal

Contributor

7095 Points

1966 Posts

### Re: lowest and highest salaries display

You need this:

`select top 5 salary from Employees order by salary DESC`

Anuj Koundal
Asp .Net Tutorials | www.codingfusion.com
Bank IFSC Codes
Ajax Control Toolkit
• Nan Yu

All-Star

18265 Points

3594 Posts

Microsoft

### Re: lowest and highest salaries display

Jan 25, 2016 06:00 AM|Nan Yu|LINK

Hi ，

Below statements are for your reference:

To get the top 5 rows order by some field:

`SELECT TOP 5[ID] FROM table ORDER BY <YourColumn> ASC/DESC`

To get only 2nd row:

```WITH Resulttable AS
(
SELECT TOP 5
*, ROW_NUMBER() OVER(ORDER BY YourColumn) AS RowNumber
FROM @Table
)
SELECT * FROM Resultstable WHERE RowNumber=2```

Best Regards,

Nan Yu

MSDN Community Support
• TechView

Participant

1778 Points

838 Posts

### Re: lowest and highest salaries display

The following should return the second highest salary:

`SELECT TOP 5 Salary AS 'Second Highest Salary' FROM (SELECT DISTINCT TOP 2 Salary FROM SalaryTable ORDER BY Salary DESC) a ORDER BY Salary ASC`

Helping others is to provide help to yourself. Mark as answer, if the solution helps.

TechView
• sandeepmitta...

Contributor

5794 Points

1185 Posts