Getting the most recent message in a thread
I have a query that gets all the info I need for a messaging system's main page (including unread message count, etc)... but it currently retrieves the original threads message. I would like to augment the below query to grab the most recent message in each thread instead. This query is very close, however my mediocre SQL skills are keeping me from wrapping things up... $messages = array(); $unread_messages_total = 0; $messages_query = " SELECT m.* , COUNT(r.id) AS num_replies , MAX(r.datetime) AS reply_datetime , (m.archived NOT LIKE '%,".$cms_user['id'].",%') AS message_archive , (m.viewed