mysql递归查询cte

Posted 一柒微笑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql递归查询cte相关的知识,希望对你有一定的参考价值。

mysql在8.0.1版本加入了cte递归查询

表结构: ||  id  ||  pid  ||  name ||

查询id为1的节点以及他所有的子孙节点

with recursive cte as (
    select * from tree where id = 1
    union all 
    select t.* from tree as t inner join cte on t.pid = cte.id
) select * from cte;

 

以上是关于mysql递归查询cte的主要内容,如果未能解决你的问题,请参考以下文章

mysql递归查询cte

SQL 递归查询,意淫CTE递归的执行步骤

PostgreSQL递归查询示例

将 CTE 应用于递归查询

sql server使用cte递归查询获取树形的父节点/子节点

使用 CTE 进行递归查询的基本条件?