MySQL根据父选择记录

时间:2022-11-11 20:42:56

I got a table with the user name and their guarantor. I want to select the record based on 1 name and follow by the guarantor and continue search next record based on this guarantor's guarantor.

我得到了一张包含用户名和保证人的表格。我想根据1名称选择记录,然后由担保人跟进,并根据担保人的担保人继续搜索下一条记录。

=========================
Name        | ParentName
=========================
Ali         | Abu
Bola        | Ali
Cat         | Bola
Danny       | Cat
Dog         | Elephant
=========================

When I put in Danny to the parameter, my expected result will be :

当我将Danny放入参数时,我的预期结果将是:

=========
Name
=========
Danny
Cat
Bola
Ali
=========

Is there any possibility to done it with query?

有没有可能用查询完成它?

1 个解决方案

#1


0  

Yes, you can do it! You need to create a recursive query using functions/procedures.

是的,你可以做到!您需要使用函数/过程创建递归查询。

Read here

在这里阅读

#1


0  

Yes, you can do it! You need to create a recursive query using functions/procedures.

是的,你可以做到!您需要使用函数/过程创建递归查询。

Read here

在这里阅读