title: MYSQL shows incorrect rows when using GROUP BY
body: <p>I have two tables: </p>
  
  <pre><code>article('id', 'ticket_id', 'incoming_time', 'to', 'from', 'message')
  ticket('id', 'queue_id')
  </code></pre>
  
  <p>where tickets represent a thread of emails between support staff and customers, and articles are the individual messages that compose a thread.</p>
  
  <p>I'm looking to find the article with the highest incoming time (expressed as a unix timestamp) for each ticket_id, and this is the query I'm currently using:</p>
  
  <pre><code>SELECT article.* , MAX(article.incoming_time) as maxtime
  FROM ticket, article
  WHERE ticket.id = article.ticket_id
  AND ticket.queue_id = 1
  GROUP BY article.ticket_id
  </code></pre>
  
  <p>For example,</p>
  
  <pre><code>:article:
  id --- ticket_id --- incoming_time --- to ------- from ------- message --------
  11     1             1234567           help@      client@      I need help...   
  12     1             1235433           client@    help@        How can we help?
  13     1             1240321           help@      client@      Want food!    
  ...
  
  :ticket:
  id --- queue_id
  1      1
  ...
  </code></pre>
  
  <p>But the result looks to be the row with the smallest article id instead of what I'm looking for which is the article with the highest incoming time.</p>
  
  <p>Any advice would be greatly appreciated!</p>