我正在尝试制作一个带子类别的下拉菜单。
这是我的MYSQL代码
SELECT root.categoryName AS root_name, root.id AS root_id, down1.categoryName AS down1_name,
down1.id AS down1_id, down2.categoryName AS down2_name, down2.equipmentID AS down2_id
FROM category AS root
LEFT OUTER
JOIN category AS down1 ON down1.parent_id = root.id
LEFT OUTER
JOIN category AS down2 ON down2.parent_id = down1.id
我得到的是
Category 1 28 Sub Category 1 63 NULL NULL
Category 1 28 Sub Category 2 61 NULL NULL
Category 1 28 Sub Category 3 62 NULL NULL
Category 2 29 Sub Category 4 71 NULL NULL
Category 2 29 Sub Category 5 70 NULL NULL
Category 3 27 Sub Category 6 30 Product 1 33
Category 3 27 Sub Category 6 30 Product 2 54
我想要的是:
-Category 1 (id)
-Sub Category 1 (id)
-Sub Category 2 (id)
-Sub Category 3 (id)
-Category 2 (id)
-Sub Category 4 (id)
-Sub Category 5 (id)
-Sub Category 6 (id)
-Category 3 (id)
-Sub Category 7 (id)
-Product 1 (id)
-Product 2 (id)
-Sub Category 2 (id)
-Sub Category 3 (id)
答案 0 :(得分:0)
您无法在一个查询中获取多维数据。你可以: