>>So, do you want to count all subcategories or just top level subcategories? In the former case we're talking about recursive CTE.
>
>The initial purpose was to count, from a parent, the number of first level child. The SQL select command I provided in the other message sums it all. I basically added a COUNT(*) with a LEFT JOIN. It is just that this forces me to MIN() all the extra fields I want or to switch into a sub select as you mention.
To only get first level subcategories count:
SELECT Category.Numero, Category.Anglais, ISNULL(SubC.Compte,0) as Compte
FROM Category
OUTER APPLY (select count(*) as Compte from Category AS Category2
where Category.Numero=Category2.NoCategory) SubC
WHERE Category.NoClient=78 AND Category.NoCategory=0
If it's not broken, fix it until it is.
My Blog