The title is a bit complex. I apologize but the query is also complex for a non-SQL person.
I have a table messages
that has the following structure:
Message(id, sender_id, receiver_id, message_datetime)
My goal is to select the last messages received by a receiver_id
from distinct senders.
When I do for example:
SELECT *
FROM `message`
WHERE `receiver_id` =1
I get something like:
1005 | 2 | 1 | 2015-11-08
1004 | 3 | 1 | 2015-11-07
1003 | 3 | 1 | 2015-11-06
1002 | 2 | 1 | 2015-11-05
1001 | 2 | 1 | 2015-11-04
While I need something like:
1005 | 2 | 1 | 2015-11-08
1004 | 3 | 1 | 2015-11-07
Your usual expert guidance is highly appreciated. I am really stuck with such a query. Thanks again and sorry for the bad formatting.