I am using a message system inside my application and i want to get the number of unread messages in his profile the schema is as follows
Users table message
user_id message_id
...... sender_id
receiver id
text
flag
flag where is use to determine whether a user has read a message or not . flag=0 user has not read a message and 1 as read
how to get the number of unread message of a particular user
SELECT message_id, count(*)
FROM message
WHERE flag=0
GROUP BY receiver_id;