title: select multiple columns with max from one column and distinct on another
body: <p>So I want to select all the records with distinct contractNo and the max versionNo.</p>
  
  <p>So I have a table like this:</p>
  
  <pre><code>| username | contractNo | versionNo |
  |===================================|
  | lucian   |     1      |     1     |
  | john     |     2      |     1     |
  | lucian   |     2      |     1     |
  | kris     |     3      |     1     |
  | lucian   |     1      |     2     |
  | david    |     4      |     1     |
  | lucian   |     1      |     4     |
  | adam     |     5      |     1     |
  | lucian   |     2      |     2     |
  | kris     |     3      |     2     |
  | lucian   |     3      |     1     |
  | lucian   |     1      |     3     |
  | lucian   |     1      |     5     |
  | lucian   |     4      |     1     |
  </code></pre>
  
  <p>and I want to select the following records:</p>
  
  <pre><code>| username | contractNo | versionNo |
  |===================================|
  | lucian   |     1      |     5     |
  | lucian   |     2      |     2     |
  | lucian   |     3      |     1     |
  | lucian   |     4      |     1     |
  </code></pre>
  
  <p>I have this query, however this only returns them in descending order ordered by contractNo and versionNo. </p>
  
  <pre><code>SELECT username, contractNo, versionNo 
  
  FROM contracts 
  
  WHERE useremail = 'lucian'
  
  order by contractNo, versionNo desc;
  </code></pre>
  
  <p>I believe that I need to do some kind of join, but I am not sure how. </p>
  
  <p>Any help would be appreciated.</p>