title: SQL - Returning distinct row for data with Max created timestamp value
body: <p>Within my program, I audit incoming data, which can be of 4 types.  If the data meets all required criteria, it gets stored with success in a table column, along with the message type and timestamp of when the row was entered into the table.</p>
  
  <p>Data can also be written to the table with error, due to something like a connection issue occurrring etc with auditing.  The program will retry auditing this data, and if succesful will write a new row, with successful.  So you see I now have 2 rows for that particular message of data, one having success, one having error, both with different time stamps.  (Success having the most recent timestamp than the error record.)</p>
  
  <p>A third message, rejected occurs and has a record written if the incoming data doesnt meet the required standard, again with a create timestamp.</p>
  
  <p>What I'd like to do, is write a Sybase SQL query to pull back only the record for each received message, with the highest timestamp.</p>
  
  <p>So with the above error example, I dont want to return the error record, only the corresponding success record from when the process retried and was a success.</p>
  
  <p>I had thought of something like the following..</p>
  
  <pre><code>SELECT distinct(*) 
      FROM auditingTable
          WHERE timestamp = (SELECT MAX(timestamp) from auditingTable)
  </code></pre>
  
  <p>though Im aware this will only bring back 1 record, with the highest timestamp in the whole table.</p>
  
  <p>How could I get back the most recent record for each message received, regardless of its status??</p>
  
  <p>Any ideas welcome!</p>