I'm building a private messaging system for a dating site..having troubles with a group by query. Here is the structure of the table:
`id` bigint (20) NOT NULL AUTO_INCREMENT ,
`fromme` integer (11) NOT NULL,
`tome` integer (11) NOT NULL,
`subject` varchar (255) NOT NULL,
`message` longtext NOT NULL,
`mydate` datetime NOT NULL,
`thread` varchar (255) NOT NULL,
`receipt` varchar (50) NOT NULL,
`INDELETE` varchar (5),
`SENTDELETE` varchar (5),
PRIMARY KEY (`id`)
When a user sends a new message to another user, it generates a random string to keep track of the thread. As they reply, it carries the thread string (similar to facebook). When a user logs in, they can see all the messages in their inbox, and based on whether it is a new message, it changes the bg color of the row. All of this is working fine, except the receipt status of a a message that has been threaded back and forth. This is the query:
select messages.id, messages.fromme, messages.subject, messages.message, messages.receipt, messages.mydate, messages.thread, users.firstname, users.lastname, users.image1
from messages, users
where messages.tome = '40' and messages.INDELETE !='y' and messages.fromme = users.id
GROUP BY messages.thread
ORDER BY messages.mydate desc
It returns it properly, but the group by function is returning the FIRST message of the thread..I need the LATEST one in order to make it work properly. Anyone know how to accomplish this?