我有一个表,其中包含顶级菜单的id、name、parentId及其子项,例如:
--------------------------------------
id | name | parentId
--------------------------------------
1 | Color | 0
--------------------------------------
2 | Flower | 0
--------------------------------------
3 | Red | 1
--------------------------------------
4 | pink | 1
--------------------------------------
5 | Rose | 2
--------------------------------------
6 | Lily | 2
--------------------------------------
我想获取这些记录,结果数组必须像
---------------------------------------------------------------
id | Pname | parentId | child | childId
---------------------------------------------------------------
1 | Color | 1 | Red | 3
---------------------------------------------------------------
2 | Color | 1 | Pink | 4
---------------------------------------------------------------
3 | Flower | 2 | Rose | 5
---------------------------------------------------------------
4 | Flower | 2 | Lily | 6
---------------------------------------------------------------
我的查询是这样的:
SELECT name AS Pname FROM myTbl WHERE id = (SELECT parentId FROM myTbl WHERE parentId = 1 )
但是mysql说 #1242 - 子查询返回超过 1 行
任何人都可以解决它吗?谢谢..