I'm a newbie in mysql and not sure if possible to have a loop statement in select.
My Table:
ID user_id parent
1 13 2
2 14 2
3 15 13
4 16 13
5 17 14
6 18 14
7 19 15
8 20 15
parent with value of 2 has no parent. it is something like root
user_id
is equivalent to child
so if i do
SELECT * FROM my_table WHERE parent = 2
basically output is:
ID user_id parent
1 13 2
2 14 2
is there a way i can get the other child? should i do subquery? If 2 is selected this is the image i want to achieve: http://awesomescreenshot.com/04b2y7qfe2