I have a table containing a list of products, some products have a parent stored in the table and I want to show the number of children that a product has.
| ProductID | ParentID |
|---|---|
| 1 ------ | ------NULL |
| 2------- | ------NULL |
| 3 ------ | -----------1 |
| 4 ------- | ----------1 |
Would Then Show As:
| ProductID | ParentID | CountOfChild |
|---|---|---|
| 1 ------ | ------NULL | --------2 |
| 2------- | -----NULL | ---NULL |
| 3 ------ | ----------1 | ---NULL |
| 4 ------- | ----------1 | ----NULL |
I Tried the Statement
SELECT ProductID, ParentID, COUNT(ParentID)
FROM Product
GROUP BY ProundID
But no success I am really not sure how to go about this.
Thanks.