title: MySQL get only the row with the highest ID of a query
body: <p>Hello Stackoverflow community,</p>
  
  <p>This is my first post here, so I apologize for my bad English! :)</p>
  
  <p>If you don't want to read everything, the Questions are marked <strong>like this</strong>.</p>
  
  <p>The title is a little misleading, but I didn't know how to explain it in a better way, but the detailed explanation should let you understand:</p>
  
  <p>I have a big log table (about 500000 rows at this time), where a game server logs many actions that occur in the game. I want to extract some specific log rows the most efficient way.</p>
  
  <p>I can't change the logging system of the game server, if I could I would change it to many more log tables, to create more compact logs. (because executing queries on that table takes it's time..)</p>
  
  <p>Now my problem is, that I want to get the last log row of a specific type and from a specific player id to get the players last action, and I don't know how to do that in an efficient way.
  Example:</p>
  
  <pre><code>SELECT * FROM log WHERE logType = "PLAYER" AND playerID = [playerID] ORDER BY time DESC LIMIT 1
  </code></pre>
  
  <p>Then the output on the website would be:
  You last action was [the human readable action and additional information].</p>
  
  <p>MySQL profiling now tells me that sorting of the results takes the most amount of time.</p>
  
  <p>Now my question is: <strong>Is it possible to get only the last row of a specific player id and type?</strong>
  I guess it could be done with the ID, cause it has auto_increment. So <strong>is it possible to get the row with the highest ID, a specific type and a specific player id?</strong></p>
  
  <p>The table structure:
  ID(int) | logType(varchar) | time(datetime) | playerID(int) | positionX(int) | positionY(int) | actionID(int) | action(varchar) | hints(varchar) | ip(varchar) | itemNumber(int)</p>
  
  <p>Explaination:</p>
  
  <p>ID: the unique id of the logged action</p>
  
  <p>logType: the type of the logged action (Example: "PLAYER" or "ITEM")</p>
  
  <p>time: the time the action occured</p>
  
  <p>playerID: the id of the player (or other id's related to that type)</p>
  
  <p>positionX: X position in the game</p>
  
  <p>positionY: Y position in the game</p>
  
  <p>actionID: an id in relation to the action (Example: If the log action is "KILLED_BY_PLAYER", then the player id of the other player who killed the player)</p>
  
  <p>action: the action that is logged (Example: KILLED_BY_PLAYER)</p>
  
  <p>hints: Some useful hints like the name of the player</p>
  
  <p>ip: The IP of the player</p>
  
  <p>itemNumber: The number of the Item, if an Item is involved, else NULL</p>
  
  <p>Thanks for your help. :)</p>