title: Select MAX(ID) mysql
body: <p>I want to group mysql record with idorig and select the max id in order to select latest record.</p>
  
  <p><strong>My database content is like that:</strong></p>
  
  <pre><code>ID     | IDORIG     | MESSAGE    | STATUS
  100    | 100        | azerty     | 2
  101    | 100        | azerty     | 1
  102    | 100        | azerty     | 1
  103    | 100        | azerty     | 0
  104    | 104        | azerty     | 0
  105    | 104        | azerty     | 0
  106    | 104        | azerty     | 0
  107    | 104        | azerty     | 0
  108    | 104        | azerty     | 0
  </code></pre>
  
  <p>My SQL request is:</p>
  
  <pre><code>SELECT MAX(id),message,idorig,status FROM messages GROUP BY idorig order by id desc
  </code></pre>
  
  <p>The sql returns the good id: <strong>102</strong></p>
  
  <p>But problem is that if I try to return status I got <strong>2</strong> not <strong>0</strong></p>
  
  <p>How can I change sql request to get the latest id with group idorig and even get the records of 102 not 100</p>