i have table called type
ID Name ParentID
---------------------
1 name1 0
2 name2 0
3 name3 1
4 name4 2
5 name1 1
i need to know how many parent (descendants) each type have EX:
ID -------- descendants
ID-> 1 (have no parent)
ID-> 3 (have 1 parent (ID->1))
ID-> 5 (have two parent ((ID->3(ID->1))))
how to made optimized sql statement do this using mysql?