sql - MySQL COUNT query in join -


i have 2 tables.

the first table member table

member table id | name 1 | user 2 | user 3 | other user 

and second table friends

friends table id | member_id | friend name | notified 1 | 1 | friend #1 | 0 2 | 1 | friend #1 | 1 3 | 2 | friend #1 | 0 4 | 1 | friend #1 | 1 5 | 2 | friend #1 | 1 

what member table information total notified friends each member.

what have done until that

select m.id m.name count(f.notified) member m left join friends f on f.member_id = m.id f.notified = 1 group m.id 

but this, not working me, because if have member not notified friends, query not included in results.

in above code example member id 3 not included in results.

any idea on how modify query in order return members no notified friends ?

kind regards merianos nikos

you can subquery in way :

select m.id, m.name, (select count(f.notified) friends f f.member_id = m.id , f.notified = 1) numfriends member m group m.id 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -