MS Sql Query
DECLARE @N int
SET @N = 1 -- Change the value here to pick a different salary rank
SELECT Salary
FROM (
SELECT row_number() OVER (ORDER BY SalaryDESC) as SalaryRank
, Salary
FROM tbl_Salary
) as SalaryCTE
WHERE SalaryRank = @N
OR
DECLARE @N int
SET @N = 1
SELECT DraftAmount
FROM tbl_DocumentParser
WHERE DraftAmount = (SELECT DISTINCT(DraftAmount)
FROM tbl_DocumentParser as e1
WHERE
(@N) = (SELECT COUNT(DISTINCT(DraftAmount)
)
FROM tbl_DocumentParser as e2
WHERE e1.DraftAmount <= e2.DraftAmount))
LINQ Query
var employee = Employees
.OrderByDescending(e => e.Salary)
.Skip(1)
.First();
If multiple employees may have equal salary and you wish to return an IEnumerable of all the employees with the second-highest salary you could do:
var employees = Employees
.GroupBy(e => e.Salary)
.OrderByDescending(g => g.Key)
.Skip(1)
.First();
MYSQL Query
SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1,1 ;