this is a table in mysql.
sub_table:
id    name    parent_id
1     sub       0     //it means this the sub has not any parents.
2     sub1      1     //it means the parent is sub
3     sub2      1
4     sub3      3
5     sub4      4
6     sub5      0
7     sub6      6
how can Give an ID number and get its root parent ID?
for example:
if ID=5 return me 1
if ID=6 return me 6
if ID=7 return me 6
SELECT id from table sub_table
WHILE parent_id != 0
BEGIN
    ...?..
END
 
     
     
    