MySQL - Recursing a tree structure

后端 未结 3 800
温柔的废话
温柔的废话 2020-12-01 16:52

I have a database table which link locations together; a location can be in a location, which can be inside another location.

location (, ....)
loc         


        
3条回答
  •  死守一世寂寞
    2020-12-01 17:37

    Since mysql statements can return only table-structured data, how do you imagine the returned tree-structure?

    It is possible to do a selection with [parent_id, child_id] table, but it requires temporary table and I've seen it done on DB2, not on MySQL.

    Check this article for implementation on tree-like structures stored in MySQL: http://articles.sitepoint.com/article/hierarchical-data-database/

提交回复
热议问题