Managing hierarchical data has some ways. One of the most important ones is Nested Set Model
. See here for implementation. Even some content management systems like Joomla, use this structure.
Update 2020: As there are some considerations on this post, I should say that now I prefer the Adjacency List Model instead of the Nested Set Model since there is less complexity in this way. Also See here for implementation.