递归N级MySQL查询

问题描述 投票:0回答:1

我正在尝试从Word Press Post / Pages建立url。我能够连接到数据库并检索所需的数据。但是,有些页面有父母,而其他页面就是父母,例如:

|id|post_name|post_parent|post_status|url
|1 |post_1   |0          |publish    |post_1
|2 |post_2   |3          |publish    |post_3/post2
|3 |post_3   |0          |draft      |post_3

我想做的就是使用MySQL查询来建立url列。目前,我正在使用一些C#代码执行此操作,但是使用SQL应该可以吗? MySQL的版本是14.14 Distrib 5.1.73。我对MySQL的版本没有任何控制。

mysql recursive-query
1个回答
0
投票

您是否需要URL = post_3 / post2 / post_2,以防id = 2?

© www.soinside.com 2019 - 2024. All rights reserved.