title: Mysql: Select last occurence of every ID
body: <p>I have multiple occurrences of a Client-ID called "IDKLIENT". I want to select the last occurrence of IDKLIENT for each ID, like</p>
  
  <pre><code>1|x  2|x
  1|y  2|y
  1|z  2|z
  </code></pre>
  
  <p>would be:</p>
  
  <pre><code>1|z
  2|z
  </code></pre>
  
  <p>I used this code:</p>
  
  <pre><code>select a.*
        from  test a inner join 
        (select Name_Kl, max(IDKLIENT) as maxid from test group by IDKLIENT) as b on a.IDKLIENT = b.maxid
  </code></pre>
  
  <p>This way, I only get the same output as with</p>
  
  <p><code>select a.*</code></p>
  
  <p>Any help is appreciated!</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit: The table also has timestamps. So I would be content, if for each ID the max(timestamp) is selected. </p>