I have a subcategorias
table and I have another anuncios
, where it has the id of the subcategory. I need to fetch all subcategories and return by subcategory the number of ads it has, the problem is that I'm already generating the subcategories with another loop from another table. How could I do that?
SELECT * from 'subcategorias'
LEFT JOIN 'anuncios' ON 'subcategorias'.'id_subcategoria' = 'anuncios'.'id_anuncio'
WHERE 'anuncios'.'status' = 1;
So basically I have to list all the subcategories, and together, make a count of how many active ads each has and then I throw this loop on the page