hoopplaya4 Posted July 25, 2009 Share Posted July 25, 2009 Hey all, I need a bit of help with my MySQL Select Statement. Basically, I have an "inbox" with several items, and some of the items are "threaded", thus, I want it to show the most recent thread at the top. My current MySQL statement works in the fact that it moves the most recent "thread_id" to the top. However, it is not displaying the most recent "message subject" (called the 'title' field), which should be associated with the thread_id. Instead, it's showing the "message subject" from the first thread_id. Here is my current SELECT statement: <?php $data = mysql_query("SELECT tblpm.thread_id, tblpm.receiver_id, tblpm.title, MAX(tblpm.content), tblpm.date_sent, tblpm.sender_id, tblpm.read_pref, MAX(tblpm.id) as unique_id, tblusers.usrFirst AS first_name, tblusers.usrLast AS last_name FROM tblpm LEFT OUTER JOIN tblusers ON tblpm.sender_id=tblusers.usrID WHERE receiver_id ='$usrID' GROUP BY thread_id ORDER BY unique_id DESC") or die(mysql_error()); I guess what I am looking for is a way to also display the most recent 'tblpm.content' field. As you can see above, I tried using MAX(tblpm.content), but apparently that does not work. Any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/167357-mysql-select-statement/ Share on other sites More sharing options...
abazoskib Posted July 26, 2009 Share Posted July 26, 2009 do you have a timestamp associated with each "message subject"? Quote Link to comment https://forums.phpfreaks.com/topic/167357-mysql-select-statement/#findComment-883497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.