title: SQL MAX(m.time) does not select the highest value
body: <p>The piece of code:</p>
  
  <pre><code>SELECT m.message, 
            MAX(m.time) AS time, 
            m.sender, 
            m.receiver, 
            m.contact, 
            u.ufirstname
  FROM( (SELECT message, 
                    receiver_uid AS receiver, 
                    sender_uid AS sender, 
                    time, 
                    receiver_uid AS contact 
               FROM messages 
              WHERE sender_uid = '$me' ) 
             UNION 
             (SELECT message, 
                     receiver_uid AS receiver, 
                     sender_uid AS sender, 
                     time, 
                     sender_uid AS contact 
                FROM messages 
               WHERE receiver_uid = '$me' ) ) AS m, 
           users AS u
     WHERE m.contact = u.uid
  GROUP BY m.contact
  ORDER BY time DESC;
  </code></pre>
  
  <p>My problem is that this piece SHOULD select the most recent message of a conversation.
  This is the format of the database:</p>
  
  <pre><code>Sender_uid | receiver_uid | message | time («What format should this be?)
  </code></pre>
  
  <p>The first part retrieves all the messages in which '$me' (=userID of logged in user) takes part. So <strong>all</strong> the messages whether '$me' is sending or receiving.
  The second part should select the most recent time (highest value) for each 'conversation' (=contact ID, whether contact is receiver or sender)</p>
  
  <p>It <strong>does not</strong> get the most recent message. It <strong>does</strong> give you one message from the conversation.</p>
  
  <p><strong>Important hint(?):</strong> What I think the script is doing is retrieving the most recent message where '$me' is the sender.</p>
  
  <p>I want it to collect the last message whether $me is receiver or sender.</p>