title: How to select max value on second primary key
body: <p>I have a table like this:</p>
  
  <pre><code>id | version | name
   1      1      name1 v1
   1      2      name1 v2
   1      3      name1 v3
   1      4      name1 v4
   2      1      name2 v1
   2      2      name2 v2
   2      3      name2 v3
  </code></pre>
  
  <p>I'm trying to get the max version of every id on the table with this query:</p>
  
  <pre><code>SELECT a.id, MAX(a.version) AS version, b.name
  FROM table1 a
  INNER JOIN (
  SELECT * FROM table1
  ) b
  ON a.id = b.id AND a.version = b.version
  GROUP BY a.id
  </code></pre>
  
  <p>But I get these results instead:</p>
  
  <pre><code> id | version | name
   1      4      name1 v1
   2      3      name2 v1
  </code></pre>
  
  <p>When I should get this:</p>
  
  <pre><code>id | version | name
   1      4      name1 v4
   2      3      name2 v3
  </code></pre>
  
  <p>Any help would be highly appreciated, thanks in advance</p>
  
  <p>EDIT:</p>
  
  <p>I just realized that adding max(b.name) in the select statement does the trick hehe</p>
  
  <p>Anyway, thanks to @bluefeet, @user2001117, @rs. and @Bram Gerritsen. All of your queries work like a charm =)</p>