Monday 28 April 2014

how to get nth highest and lowest salary in sql server

Ex Code: Lowest case :

select top 1 column as 'salary' from (select distinct top 4 column from  Table order by ID asc) a order by ID desc

Highest Case:

select top 1 column as 'salary' from (select distinct top 4 column from  Table order by ID desc) a order by ID asc

Tuesday 1 April 2014

linq get second highest number or salary

Use this query:

var employees = Employees
    .GroupBy(e => e.Salary)
    .OrderByDescending(f => f.Key)
    .Skip(1).Take(1)
    .First();