Recursive COUNT Query (MS SQL)
- by Cosmo
Hello Guys!
I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories.
Category
Id : bigint (PK)
Name : nvarchar(255)
AcceptQuestions : bit
IdParent : bigint (FK)
Question
Id : bigint (PK)
Title : nvarchar(255)
...
IdCategory : bigint (FK)
How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(