I have the following query in my application. It works well, but I need it to also contain the number of products that are associated with each manufacturer.
The current
select *
from `manufacturers` m
inner join `languages` l on m.`lang` = l.`id`
left outer join (
select manufacturerid, count(*) as ProductCount
from Products
group by manufacturerid
) pc on m.id = pc.manufacturerid
order by l.`id` asc, m.`id` asc
SELECT `manufacturers`.*, `languages`.*, COUNT(`products`.`id`) AS NumberOfProducts
FROM (`manufacturers`)
JOIN `languages` ON `manufacturers`.`lang` = `languages`.`id`
LEFT OUTER JOIN `products` ON
`products`.`manufacturerid` = `manufacturers`.`manufacturerid`
GROUP BY <Column list for manufacturers AND languages here>
ORDER BY `languages`.`id` asc, `manufacturers`.`id` asc