title: Find max and second max salary for a employee table MySQL
body: <p>Suppose that you are given the following simple database table called Employee that has 2 columns named Employee ID and Salary:</p>
  
  <pre><code>  Employee
    Employee ID    Salary
     3            200
     4            800
     7            450
  </code></pre>
  
  <p>I wish to write a query select max(salary) as max_salary, 2nd_max_salary from employee</p>
  
  <p>then it should return</p>
  
  <pre><code>  max_salary   2nd_max_salary
     800             450
  </code></pre>
  
  <p>i know how to find 2nd highest salary </p>
  
  <pre><code>   SELECT MAX(Salary) FROM Employee
    WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )
  </code></pre>
  
  <p>or to find the nth </p>
  
  <pre><code>  SELECT FROM Employee Emp1 WHERE (N-1) = ( SELECT COUNT(DISTINCT(Emp2.Salary)) FROM Employee Emp2
    WHERE Emp2.Salary &gt; Emp1.Salary)
  </code></pre>
  
  <p>but i am unable to figureout how to join these 2 results for the desired result</p>