I have a category table (brands) and 2 other tables (
Pencils) that have parent-child relation with this table through a field
CatID. Now I want to get a list of
Brandsand number of records in child tables.
I use this query:
Select B.* ,COUNT(P.ID) as PensCount, COUNT(Pc.ID) as PencilsCount from Brands B left outer join Pens P on B.ID=P.CatID left outer join Pencils Pc on B.ID= Pc.CatID group by B.ID,B.Title;
Is this correct? Is there any way to make this query better?