I am trying to make a message system, and what i want to do is display the last message posted grouped by the FromMemberID, so basically it will list all the senders, display the last message received by each sender.
CREATE TABLE Messages (
MessageID int(9) NOT NULL auto_increment,
ToMemberID mediumint(9) NOT NULL default '0',
FromMemberID mediumint(9) NOT NULL default '0',
Subject varchar(100) NOT NULL default '',
Message text NOT NULL,
DateTime datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (MessageID)
)
SELECT Subject, Message, FromMemberID
FROM Messages
WHERE ToMemberID = 1192361
GROUP BY FromMemberID
ORDER BY MessageID DESC
From what i can tell that should do it, but it does not show the last message, it still displays the first message, what am i doing wrong?
i have tried this as well, and it still only shows the very first message sent by each user, not the latest
SELECT Subject, Message, FromMemberID, MAX(MessageID)
FROM Messages
WHERE ToMemberID = 1192361
GROUP BY FromMemberID
anyone have any ideas?