Reputation: 546
i need such a query where child and parent field are given with a relationship, each child has a parent and this parent is a child of other parent and so on. In this query i need a sequence of child to parent until parent is not NULL.
as like if i start from Daniel then the relult should be
| Elec |
| Flyo |
| Sad |
The table parent_child given below,
child | parent
----------------------
Sad | NULL
Buddy | Clone
Clone | Daniel
Daniel | Elec
Elec | Flyo
Flyo | Sad
Upvotes: 1
Views: 119
Reputation: 39981
It is not possible with a single query but you can write a recursive function that calls it self until the answer is found.
Upvotes: 1