1

晚上

我有两张桌子:网址和地点。为了简化,数据是这样的:

网址:

urlID    url
1        /england
2        /scotland
3        /wales

地点:

placeId    name        lft    rgt       urlRef
1          England     1      23000     1
2          Scotland    23001  37000     2
3          Wales       37001  50000     3

然后,places 表在国家/地区内嵌套了更多的地方。我希望能够加入这两个表来选择我的位置的路径,例如:

England     /england
Shropshire  /england/shropshire
Shrewsbury  /england/shropshire/shrewsbury

我首先尝试了这个,它不起作用,其他各种方法也没有。

SELECT node.name, url 
FROM places AS node, places AS parent LEFT JOIN urls ON urlId = node.urlRef
WHERE node.lft BETWEEN parent.lft AND parent.rgt AND urlId = 1
ORDER BY node.lft
4

1 回答 1

0

您需要加入父节点:

SELECT parent.placeId, parent.name, parent.type, parent.ico, url
FROM places AS node, urls LEFT JOIN places AS parent ON parent.urlRef = urls.urlId
WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.urlRef = :urlId
ORDER BY parent.lft
于 2012-05-22T14:16:21.607 回答