mySQL query for selecting children

前端 未结 7 916
失恋的感觉
失恋的感觉 2020-12-20 05:59

I am not sure if this is possible in mySQL. Here are my tables:-

Categories table:

  • id
  • name
  • parent_id (which points to Categories.id)<
相关标签:
7条回答
  • 2020-12-20 06:51

    Assuming MySQL, it'll be difficult to avoid recursion in PHP.

    Your question is, essentially, how to mimic Oracle's CONNECT BY PRIOR syntax in MySQL. People ask this question repeatedly but it's a feature that's never made it in to MySQL and implementing is via stored procedures probably won't work because (now) stored functions cannot be recursive.

    Beware of the database kludges offered so far.

    The best information so far are the three links from nawroth:

    • Managing Hierarchical Data in MySQL, including the Nested Set Model.
    • Trees in SQL - nested set model by Joel Celko
    • Troels' links: Relational database systems: Hierarchical data in RDBMSs
    0 讨论(0)
提交回复
热议问题