Aug 8, 2015

Linq query for find the 2nd Highest salary..

var employee = Employees
    .OrderByDescending(e => e.Salary)
    .Skip(1)
    .First();


If inside your table contain duplicate records means 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(f => f.Key)
    .Skip(1)
    .First();


No comments:

Post a Comment