I have two tables broadcast
and contact
and I want the count of the number of recipients in that particular broadcast if there is no user still all broadcast lists should be displayed. for this, I got my desired output with this left join Query.
SELECT b.id, b.brl_name, COUNT(c.broadcast_list_id) AS Recepients FROM broadcastlistsms b LEFT JOIN addcontact c ON b.id = c.broadcast_list_id GROUP BY b.id,b.brl_name;
But I have 2 common fields in both tables that are created_by and isdeleted, isdeleted(1) is that particular contact and broadcast is deleted. So I want to get only that contact count which is not deleted and created by a particular user. and similarly to broadcast, the broadcast should not be deleted and created by the particular user.
I tried this but it did not give broadcast entry which has 0 contacts.
SELECT b.id, b.brl_name, COUNT(c.broadcast_list_id) AS Recepients FROM broadcastlistsms b LEFT JOIN addcontact c ON b.id = c.broadcast_list_id
WHERE (b.createdby_id = 1 and b.isdeleted = 0) and (c.createdby_id = 1 and c.isdeleted = 0)
GROUP BY b.id,b.brl_name;
In the future will have 3 more fields in the contact table like isdeleted, then also I need to check all of that 3 field and need a count value as per that field.
Here is the Fiddle link : Fiddle