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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.