title: MySQL - How to select rows with max value of a field
body: <p>I have a table of users with their scores for each level of a game:</p>
  
  <pre><code>id | user_id | level | score
  1  | David   | 1     | 20
  2  | John    | 1     | 40
  3  | John    | 2     | 30
  4  | Mark    | 1     | 60
  5  | David   | 2     | 10
  6  | David   | 3     | 80
  7  | Mark    | 2     | 20
  8  | John    | 3     | 70
  9  | David   | 4     | 50
  10 | John    | 4     | 30
  </code></pre>
  
  <p>What is the SQL query needed to get for each level, who has the highest score?</p>
  
  <p>The result should be:</p>
  
  <pre><code>id | user_id | level | score
  4  | Mark    | 1     | 60
  3  | John    | 2     | 30
  6  | David   | 3     | 80
  9  | David   | 4     | 50
  </code></pre>
  
  <p>Thank you</p>