Jump to content

MySQL SELECT Statement


hoopplaya4

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/167357-mysql-select-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.