I have mysql table. in that table i have two columns called id_category
and id_parent
.
id_category | id_parent
1 | 0
2 | 1
3 | 1
4 | 1
5 | 3
6 | 2
7 | 2
8 | 2
9 | 5
10 | 9
11 | 9
12 | 11
13 | 11
id_category
is auto increment and id_parent
have the category values. here i want to get the root id_category for id_category
=13 which is equal to id_parent
=1. it goes like zigzag l.e id_cat =13 so id_parent=11, so now id_cat =11 so id_parent=9, id_cat =9 so id_parent=5, id_cat =5 so id_parent=3, id_cat =3 so id_parent=1 now condition meet . now i want the category id which have parent id = 1.. in this query expected answer is id_category=3. here for id_category=13 the id_category=3 is the root category this is what i exactly want . now i dont know how to write the query please help me. thanks in advance