My table is a messaging table basically. I have the following fields:
id: integer, sender_id: integer, receiver_id: integer, message: text
what i want to do is get the COUNT of rows of messages for each pair of sender and receiver.
Say for example:
- user ID 10 sent 3 messages to user 12.
- user 12 sent 2 messages to user 10
- user 3 sent 1 message to user 4
- user 4 sent 1 message to user 3
I want the result to show the number of messages exchanged between 10 and 12, in this case, there should be 5.
Likewise for users 3 and 4, should show that they have exchanged 2 messages.
All in one query if possible.
I hope I make sense.
However that will count any messages they have sent to them self. For example 10->10. So to be exact: