I have a mysql database table which has list of locations with there parent location id in hierarchical manner so i want to list all the locations with their root parent location
Following is the sample table
id location_name parent_id 1 a 0 2 b 0 3 c 0 4 d 1 5 e 1 6 f 5 7 g 4 8 k 2 9 l 8 10 j 9
Following is the result i want
id location_name root_parent_name 1 a a 2 b b 3 c c 4 d a 5 e a 6 f a 7 g a 8 k b 9 l b 10 j b
parent name is root parent location