Write LINQ query to find nth highest salary?

You can find nth highest salary by writing the following query.

DataContext context = new DataContext();
var q = context.tblEmployee.GroupBy(ord = > ord.Salary).OrderByDescending(f = > f.Key).Skip(1) //second, third ..nth highest salary where n=1,2...n-1
.First().Select(ord = > ord.Salary).Distinct();

 

Tagged , . Bookmark the permalink.

Leave a Reply