I have a ChatMessage table and i want to select user chats history as a list of latest message he/she has with others or himself like whast app.
when you open whats app you will see a list of your chats history that show the latest chat.
table schema is like this:
SenderId ReciverId Message
--------------------------------
1 2 hello
1 2 how are you?
2 1 hey
2 1 i'm fine
2 2 for myself
2 3 are you there?
i tried with this query:
SELECT MAX(SenderID), ReciverID, Message
FROM ChatMessages
WHERE SenderID = 2 OR ReciverID = 2
GROUP BY SenderID, ReciverID order by SenderID
the result for this query is :
senderId ReciverId Message
--------------------------------
1 2 how are you?
2 1 i'm fine
2 2 for myself
2 3 are you there?
row number 1 and 2 must be merge and just show: 2 1 i'm fine
and the result i'm looking for is:
senderId ReciverId Message
--------------------------------
2 1 i'm fine
2 2 for myself
2 3 are you there?
what is the solution? and if possible in in linq or lambda?