Table strucutre
CREATE TABLE IF NOT EXISTS `mail_box` (
`msg_id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`message` text NOT NULL,
`date` timestamp NOT NULL,
`attachment` varchar(255) NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Need the query for listing the latest 5 messages from each user.
Query I tried for Dashboard listing
SELECT usr.name as Receiver,usr1.name as Sender, message,date
FROM mail_box
JOIN users as usr on usr.id = receiver_id
JOIN users as usr1 on usr1.id = sender_id
ORDER BY date DESC
LIMIT 5
This query is limiting my result to 5 not showing the latest 5 messages from each user.