![](/img/trans.png)
[英]SELECT an arbitrarily deep tree that is represented by the adjacency list model in mysql?
[英]mysql, get tree comments with pagination (adjacency list)
我已經閱讀了很多關於mysql樹鄰接列表的信息
我想顯示最近的 10 條評論和對此評論的所有回復(或者 10 條評論where parentId is null and level = 1
,但在exists parentId and level = 2
的地方獲取所有評論)
我的數據表:
您可以使用公用表表達式。 類似於以下代碼:
WHIT
CTE1 AS (SELECT * FROM comments WHERE parentId is null and level = 1)
SELECT * FROM CTE1
UNION ALL
SELECT * FROM Comments WHERE parentId IN (SELECT id FROM CTE1) AND level = 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.