Find number of levels in a tree using MySQL

Viewed 256

My rows have related row and those rows can have related rows. This tree can go down many levels (unknown). How can I find the number of levels my tree is according to one parameter?

For example:

select * from category a 
inner join category b on a.row=b.relatedRow 
inner join category c on b.row=c.relatedRow where a.row=?

So if there are items in a, level 1. If there are items in b, level 2 and so on. This way I can find that if row=1, there are 3 levels of other items that are related.

1 Answers
Related