Fetching number of unread messages from MySQL -
i developing android chat application. have 2 tables.
table: chats id sender_id receiver_id message read_status sender_name 1 22 11 hi.. 1 raaj 2 22 11 hey. 1 raaj 3 22 11 nice. 0 raaj 4 22 11 wow 0 raaj 5 22 11 thanx 0 raaj 6 11 22 yup 0 deep 7 33 11 hi.. 1 sanju
table read: id status 0 unread 1 read
users id--> 22 -->raaj id-->11--->deep id--->33--->sanju
i have distinct sender_id , sender_name , no. of unread messages sender_id != '11'
i need result this:
sender_id sender_name no_of_unread_messages 22 raaj 3 33 sanju 0
how can in mysql using 1 query?
select sender_id, sender_name, count(*) no_of_unread_messages chats sender_id != 11 , read_status=0 group sender_id
if need records sum = 0 try one:
select sender_id, sender_name, sum(if(read_status=0,1,0)) no_of_unread_messages chats sender_id != 11 group sender_id
Comments
Post a Comment