SELECT t.id_type, brand, model, countMod FROM types t
LEFT JOIN (
SELECT p.id_type, brand, model, COUNT( model ) AS countMod
FROM products p
GROUP BY brand) p2
ON t.id_type = p2.id_type
WHERE t.id_type = "TCE"
ORDER BY brand
This query works alright but I lose the models which are grouped, of course, under each brand.
Is there a way to have the models listed and counted?
I.e. brand1, model1, model2, model3, countMod=3 -- brand2, model1, model2, countMod=2.
Any help will be greatly appreciated. Thanks