0
檢索數據我有一個包含ID,名,頂層菜單&的parentId的表自己的孩子一樣:MySql的來自同一個表
--------------------------------------
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行
誰能解決呢? 謝謝..
少許change.SELECT t1.name爲 '父',t1.id爲 '父ID',t2.name爲 '兒童',t2.id爲「孩子ID' 從我的表t1 INNER JOIN mytable t2 ON t1.id = t2.parentId – 2010-12-21 09:04:24