title: mysql get last message in conversation
body: <p>I'm currently creating an inbox of private messages and want to show the last message that was either sent or received between each unique user. I currently have this</p>
  
  <pre><code>SELECT
   Message.id, Message.from, Message.body, Message.isread, Message.timestamp,
   User.id, User.username,
  FROM messages as Message 
   LEFT JOIN users as User ON (Message.from = User.id)
      WHERE Message.id IN
       (SELECT MAX(`id`) FROM `messages` 
          WHERE `to` = '.$this-&gt;currentUser["id"].'
           OR `from` = '.$this-&gt;currentUser["id"].'
      GROUP BY `from`,`to`)
   ORDER BY Message.id DESC;
  </code></pre>
  
  <p>But it gets both the last sent AND received message, I just want <strong>the</strong> last message that was sent between the current user and any other one and the user that the conversation is with. </p>
  
  <pre><code> `Message`.`id` is auto incremented, indvidual message id.
   `Message`.`from` is the ID of the user the message is from.
   `Message`.`to` is the ID of the user the message us to.
  </code></pre>
  
  <p>Thanks</p>