Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中获取递归父级_Mysql_Join_Tree_Parent - Fatal编程技术网

如何在mysql中获取递归父级

如何在mysql中获取递归父级,mysql,join,tree,parent,Mysql,Join,Tree,Parent,我有下面的行结构,它必须显示特殊行的所有祖先 我将编写简单的查询,但不工作 select * from table1 as a join table1 as b on (a.parent_id = b.id ) where a.id = 4 ======================== 期望输出: 2 1 MySQL没有任何内置的“分层”工具。您需要在应用程序代码或存储过程的循环中编写SELECT 2 1

我有下面的行结构,它必须显示特殊行的所有祖先


我将编写简单的查询,但不工作

select * from table1 as a
join table1 as b on (a.parent_id = b.id )
where a.id = 4
========================

期望输出:

2
1

MySQL没有任何内置的“分层”工具。您需要在应用程序代码或存储过程的循环中编写
SELECT

2
1