How to count between two users unread messages in SQL
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