如何找到我所有项目的 parentId (mySQL)? (可能有无限数量的层次结构......不是最好的设计,但它是我正在使用的)
ID PARENTID NAME
9146 NULL thing1
9147 NULL thing2
9148 9146 thing3
9149 9148 thing4
9150 NULL thing5
9151 9149 thing6
9152 9147 thing7
输出应该是:
ID REAL_PARENTID
9146 NULL (or self 9146)
9147 NULL (or self 9147)
9148 9146
9149 9146
9150 NULL (or self 9150)
9151 9146
9152 9147
最佳答案
关于mysql - SQL在同一个表中递归查找父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9315737/