title: Get the second highest salary of the employees using LINQ
body: <p>I have the following entity</p>
  
  <pre><code>public class Employee
  {
      public int EmployeeID { get; set; }
      public string EmployeeName { get; set; }
      public string Department { get; set; }
      public long Salary { get; set; }
  }
  </code></pre>
  
  <p>I am trying to find out the second highest salary for the employees of every individual department using LINQ.</p>
  
  <p>So far here is what I have done</p>
  
  <pre><code> var Query = (from emp in Employees
                orderby emp.Salary descending
                group emp by emp.Department into g
                select new
                {
                    id = g.Select(i=&gt;i.EmployeeID),
                    sal  = g.Select(s=&gt;s.Salary),
                    name = g.Select(n=&gt;n.EmployeeName),
                    dept = g.Select(d=&gt;d.Department)
                }
  
                ).Skip(1).ToList();
  </code></pre>
  
  <p>But this query is not working.,</p>
  
  <p>E.g.</p>
  
  <p>Suppose I have</p>
  
  <pre><code>EmployeeID = 1,EmployeeName  ="A", Department ="Dept1", Salary = 10000
  EmployeeID = 2,EmployeeName ="B", Department ="Dept1", Salary = 20000
  EmployeeID = 3,EmployeeName ="C"  Department ="Dept1", Salary = 20000
  EmployeeID = 4,EmployeeName="D",  Department ="Dept1", Salary = 30000
  EmployeeID = 5,EmployeeName  ="A1", Department ="Dept2", Salary = 12000
  EmployeeID = 6,EmployeeName ="B1", Department ="Dept2", Salary = 4500
  </code></pre>
  
  <p>The expected output will be</p>
  
  <pre><code>EmployeeID = 2,EmployeeName ="B", Department ="Dept1", Salary = 20000
  EmployeeID = 3,EmployeeName ="C"  Department ="Dept1", Salary = 20000
  EmployeeID = 6,EmployeeName ="B1", Department ="Dept2", Salary = 4500
  </code></pre>
  
  <p>in the result set</p>
  
  <p>Using C#3.0 and Dotnet framework 3.5</p>