title: How to return the X greatest rows for each row in a table
body: <p>Assume I have two tables(below). What is the best way to write a select to get the 2 employees with the highest salary from each department? Assume that there are potentially a lot of departments.</p>
  
  <p>output: </p>
  
  <pre><code>employee_name | salary | department_id
  John          | 65000  | 1
  Sally         | 60000  | 1
  Lucy          | 40000  | 2
  James         | 80000  | 3
  Harry         | 65000  | 3
  </code></pre>
  
  <p>Tables:</p>
  
  <p><strong>Employee</strong></p>
  
  <pre><code>employee_name | salary | department_id
  John          | 65000  | 1
  Sally         | 60000  | 1
  Connor        | 55000  | 1
  Judy          | 55000  | 1
  Lucy          | 40000  | 2
  James         | 80000  | 3
  Harry         | 65000  | 3
  Penny         | 56000  | 3
  </code></pre>
  
  <p><strong>Department</strong></p>
  
  <pre><code>department_id | name
  1             | Sales
  2             | Marketing
  3             | IT
  </code></pre>