2016-06-13 52 views
0

在另一個表中的多個價值列值我有一個表:

enter image description here如何證明與在MySQL



那麼B表:

enter image description here



最後一個, ç表:

enter image description here


我需要告訴他們是這樣的:

performance_id | quiz_id 
________________________ 
22    | 65 
23    | null 
24    | 43 
25    | null 

我想加入,但它顯示出錯誤的結果。它不顯示測驗ID。我嘗試這樣做:

SELECT A.performance_id, C.quiz_id 
FROM A 
LEFT JOIN B ON A.performance_id=B.performance_id 
LEFT JOIN C ON B.phc_id = C.phc_id 
group BY A.performance_id; 

結果:
enter image description here
幫助我,謝謝

+0

提示:'LEFT JOIN' – Blank

+0

顯示你已經試過,什麼輸出爲 – Jens

+0

,請看到我的編輯問題@Reno –

回答

1

使用group_concat

SELECT A.performance_id, group_concat(C.quiz_id) 
FROM A 
LEFT JOIN B ON A.performance_id=B.performance_id 
LEFT JOIN C ON B.phc_id = C.phc_id 
group BY A.performance_id; 

因爲你得到一個以上的quiz_id

0

試試這個

SELECT A.performance_id, group_concat(C.quiz_id) 
FROM A 
LEFT JOIN B ON A.performance_id = B.performance_id 
LEFT JOIN C ON B.phc_id = C.phc_id 
group BY A.performance_id; 

SQL Fiddle