mysql递归查询方式

WITH RECURSIVE cte AS(
SELECT a.*  FROM tab a where a.pid='1'
UNION ALL
SELECT k.* FROM tab k INNER JOIN cte c ON c.id= k.pid
)SELECT * FROM cte

pid:上级ID

ID:自身ID

posted @ 2023-10-12 09:42  天涯已可  阅读(6)  评论(0编辑  收藏  举报