I have two tables in MySql Company : (cname,city) works : (ename,cname,salary)
I want to display number of employees working for every company, even if that number i
Try
Select company.cname, count(work.id) from company left join work on ....=.... group by company.cname
where you fill out the "...." parts, and change the work.id to you name
Classic case for a LEFT JOIN:
SELECT
c.cname,
COUNT(w.ename) wcount
FROM
company c
LEFT JOIN works w ON c.cname = w.cname
GROUP BY
c.cname
There is another way to do so with subquery, here is a sample from my case:
select count(`order_id`) as cnt
from (
select `order_id` from `room_bookings`
where `room_id` = 3 and `day_id` = 20180201
group by `order_id`
) as b;