title: MySQL Query performance improvement for order by before group by
body: <p>below is a query I use to get the latest record per <code>serverID</code> unfortunately this query does take endless to process. According to the stackoverflow question below it should be a very fast solution. Is there any way to speed up this query or do I have to split it up? (first get all serverIDs than get the last record for each server) 
  <a href="https://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group">Retrieving the last record in each group</a></p>
  
  <pre><code>SELECT s1.performance, s1.playersOnline, s1.serverID, s.name, m.modpack, m.color
      FROM stats_server s1 
      LEFT JOIN stats_server s2
          ON (s1.serverID = s2.serverID AND s1.id &lt; s2.id)
      INNER JOIN server s
          ON s1.serverID=s.id
      INNER JOIN modpack m
          ON s.modpack=m.id
      WHERE s2.id IS NULL
      ORDER BY m.id
  15 rows in set (34.73 sec)
  </code></pre>
  
  <p><strong>Explain:</strong></p>
  
  <pre><code>+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
  | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra            |
  +------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
  |    1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | Impossible WHERE |
  +------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
  1 row in set, 1 warning (0.00 sec)
  </code></pre>
  
  <p><strong>Sample Output:</strong></p>
  
  <pre><code>+-------------+---------------+----------+---------------+-------------------------+--------+
  | performance | playersOnline | serverID | name          | modpack                 | color  |
  +-------------+---------------+----------+---------------+-------------------------+--------+
  |          99 |            18 |       15 | hub           | Lobby                   | AAAAAA |
  |          98 |            12 |       10 | horizons      | Horizons                | AA00AA |
  |          97 |             6 |       11 | m_lobby       | Monster                 | AA0000 |
  |          99 |             1 |       12 | m_north       | Monster                 | AA0000 |
  |          86 |            10 |       13 | m_south       | Monster                 | AA0000 |
  |          87 |            17 |       14 | m_east        | Monster                 | AA0000 |
  |          98 |            10 |       16 | m_west        | Monster                 | AA0000 |
  |          84 |             7 |        5 | tppi          | Test Pack Please Ignore | 55FFFF |
  |          95 |            15 |        6 | agrarian_plus | Agrarian Skies          | 00AA00 |
  |          98 |            23 |        7 | agrarian2     | Agrarian Skies          | 00AA00 |
  |          74 |            18 |        9 | agrarian      | Agrarian Skies          | 00AA00 |
  |          97 |            37 |       17 | agrarian3     | Agrarian Skies          | 00AA00 |
  |          99 |            17 |        3 | bteam_pvp     | Attack of the B-Team    | FFAA00 |
  |          73 |            44 |        8 | bteam_pve     | Attack of the B-Team    | FFAA00 |
  |          93 |            11 |        4 | crackpack     | Crackpack               | EFEFEF |
  +-------------+---------------+----------+---------------+-------------------------+--------+
  15 rows in set (38.49 sec)
  </code></pre>
  
  <p><strong>Sample Data:</strong></p>
  
  <p><a href="http://www.mediafire.com/download/n0blj1io0c503ig/mym_bridge.sql.bz2" rel="nofollow noreferrer">http://www.mediafire.com/download/n0blj1io0c503ig/mym_bridge.sql.bz2</a></p>