I am creating a simple chat module where there are two levels.
- Inbox
- Conversation
in the Inbox i want to list the conversation between me and other users and display the latest chat message from that particular user.
messages(id, user_id, receiver_id, message, timestamp)
Dummy data
1, 1, 2, "hi there", today 2, 1, 4, "Hey Tommy", yesterday 3, 1, 2, "Wanna meet tonite?", now
Now when i display the list i want to just display two messages
one with user id – 4 and user id 2. But the latest message of userid 2 should be displayed only.
How to do a query where i can get only the latest row from a particular user ?
This is beleive is an efficient way to acheive this: