SQL PRACTICE: SQL SERVER - Third Highest Salary
Q9. How to find the third highest salary from the table below using SQL?
N.B: I am using the following:
Database -> MSSQL
SQL Dialect -> T-SQL
Consider below an employment table as a source data.
Table 1. Employment Table
Ans:
select top 1 salary from (
select top 3 salary
from employment
order by salary desc) as TopThree
order by salary asc;
Explanation: To find the third highest salary from the provided table, first I need to find the first three rows with highest salary ordered in descending order. Look at the the query and result below.
select top 3 salary
from employment
order by salary desc;
Comments
Post a Comment