表名:tb_menublog
內容以下:im
查詢ID爲3的全部無限層下級會員查詢
WITH T
AS(
SELECT * FROM tb_menu WHERE id=3
UNION ALL
SELECT a.* FROM tb_menu a INNER JOIN T ON a.parent=T.id
)
SELECT * FROM Timg
結果圖以下:co
查詢Id爲3全部的上級ps
WITH T
AS(
SELECT * FROM tb_menu WHERE id=3
UNION ALL
SELECT a.*
FROM tb_menu a INNER JOIN T ON a.id=T.parent
)
SELECT * FROM Tab
結果以下圖: