How to count between two users unread messages in SQL I am creating between two users unread message count script in SQL.  

My script problem not counting between two users unread messages.
My script problem all users unread messages display as a same results.

Like this

user1 unread message 2
user2 unread message 2
user3 unread message 2


I want to get like this results

user1 unread message 2
user2 unread message 7
user3 unread message 4


Here is my link http://sqlfiddle.com/#!9/299d64/3/0
to find out which user has which number of unread messages use this.

SELECT to_id, COUNT(*)
FROM pm
WHERE readd = 0
GROUP BY to_id


So you filter by readd to get only unread messages. Then you will group by the recievers id so that you can get the number of those messages per each reciever.

If you need a more detailed view how many unread messages came from the same sender, use sommthing like this.

SELECT to_id, from_id, COUNT(*)
FROM pm
WHERE readd = 0
GROUP BY to_id, from_id