SQL tree traversal

前端 未结 3 1602
抹茶落季
抹茶落季 2020-12-18 11:12

I am not totally sure I am naming this right, but please bear with me.

I am wondering if is possible to do something like this in SQL(MySQL specifically): Let\'s say

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 11:59

    It's possible to fetch all descendants utilizing solely SQL, but not in a single query. But I'm sure you figured that out; I assume you mean you want to do it in a single query.

    You might be interested in reading about some alternative designs to store tree structures, that do enable you to fetch all descendants using a single SQL query. See my presentation Models for Hierarchical Data with SQL and PHP.

    You can also use recursive SQL queries with other brands of database (e.g. PostgreSQL), but MySQL does not currently support this feature.

提交回复
热议问题