table(ms_replies)
|------------------------------------------|
| id | ticketID | replyStamp |
|------------------------------------------|
| 1 | 7 | Tue 11 Oct 2011, 8:56am |
| 2 | 7 | Wed 12 Oct 2011, 9:20am |
| 3 | 8 | Wed 12 Oct 2011, 16:24pm |
| 4 | 7 | Thu 27 Oct 2011, 20:28pm |
| 5 | 8 | Tue 18 Oct 2011, 9:54am |
|------------------------------------------|
The code I have thus far is:
SELECT
ticketID,
MAX(replace(replace(replyStamp, 'pm',''), 'am','')) AS time
FROM
ms_replies
WHERE
`ticketID` IN ($IDs)
GROUP BY
ticketID
But this doesn’t return the most recent entry.
Please note the replace in the query is necesary to remove the am | pm , this is not my doing, but I cannot chage it, unfortunatly.
You have to convert your strings into dates if you want to compare them as dates:
But it’s actually not required if the latest entry always have the max id (as in your sample); then you can just check MAX(id) instead, like in @ZaneBien answer – or here: