Home > Net >  How to count number of user chat with another user
How to count number of user chat with another user

Time:01-27

I try few mysql statement but didn't come to my expectations.

enter image description here

How to get the total of to_user chat and order by the lowest total?

Let say in this case,

id 7 chat with 2 user

id 6 chat with only 1 user.

so the minimum will be id 6.

Can someone help me with sql statement?

This is what my expected result

count to_user
1 7
2 6

CodePudding user response:

I think your problem will be solved with the following code:

SELECT COUNT(DISTINCT(from_user)) AS total,to_user
FROM chats
GROUP BY to_user
ORDER BY total ASC
  • Related