title: MySQL selecting max record in group by
body: <p>I am trying to create a query in a table that has some 500,000 records and some 50 or 60 columns. What I need is to collate these records into groups and select the max record in each group.</p>
  
  <p>To simplify the problem I have a table as follows</p>
  
  <pre><code>+----+-------------+----------+--------+
  | id | external_id | group_id | mypath |
  +----+-------------+----------+--------+
  |  1 |        1003 |        1 | a      | 
  |  2 |        1004 |        2 | b      | 
  |  3 |        1005 |        2 | c      | 
  +----+-------------+----------+--------+
  </code></pre>
  
  <p>The simple group by is as follows</p>
  
  <pre><code>select * from temp GROUP BY group_id
  </code></pre>
  
  <p>which returns</p>
  
  <pre><code>+----+-------------+----------+--------+
  | id | external_id | group_id | mypath |
  +----+-------------+----------+--------+
  |  1 |        1003 |        1 | a      | 
  |  2 |        1004 |        2 | b      | 
  +----+-------------+----------+--------+
  </code></pre>
  
  <p>Nice but not what I want. What I want is the entire record for max enternal_id in each group. In other words</p>
  
  <pre><code>+----+-------------+----------+--------+
  | id | external_id | group_id | mypath |
  +----+-------------+----------+--------+
  |  1 |        1003 |        1 | a      | 
  |  3 |        1005 |        2 | c      | 
  +----+-------------+----------+--------+
  </code></pre>
  
  <p>Somehow I am looking to put a max(external_id) statement in here to filter what is needed but so far all my investigation has failed. Some guidance would be appreciated. It is important that when returning the max(external_id) that the entire record is selected as the path column differs.</p>