I have the following data in table categories
:
id parent_id title
-----------------|-------------------
1 0 |A
2 1 |B
3 2 |C
4 3 |D
5 4 |E
Now I want to get the root category title(parent_id 0) for category id 4 and that is category id 1 of title A.
How can I achieve the required result in a single mysql query? I assume procedural query will be used but I dont know how to do it.