我嘗試一次得到3個表數據,表是:MySQL查詢一次
- 候選人
- 語言
- candidates_language
每它代表的一些有關我數據庫中所有用戶的數據。
由於姓名建議,第一張表包含一些常規數據,例如名字,姓氏,電子郵件。
candidates
------------------------------------------------------------------------
| id | firstname | surname | email |
------------------------------------------------------------------------
| 22 | John | Doe | [email protected] |
------------------------------------------------------------------------
| 23 | Peter | Miller | [email protected] |
------------------------------------------------------------------------
第二個只包含languages_id和languageName
languages
---------------------------------
| languageID | languageName |
---------------------------------
| 1 | English |
---------------------------------
| 2 | German |
---------------------------------
| 3 | Spanish |
---------------------------------
而最後一個嘗試連接這一切在一起:
candidates_language
(foreign keys: candidates_id to table candidates,languageID to languages)
-----------------------------------------------------------------
| id | candidates_id | languageID | skill |
-----------------------------------------------------------------
| 1 | 22 | 1 | basic |
-----------------------------------------------------------------
| 2 | 22 | 3 | basic |
-----------------------------------------------------------------
| 3 | 23 | 1 | advance |
-----------------------------------------------------------------
| 4 | 23 | 2 | basic |
-----------------------------------------------------------------
我需要的結果從僅僅是這個3個表連接具體語言如下:
---------------------------------------------------------------------------
| id | firstname | surname | email | english | german |
---------------------------------------------------------------------------
| 22 | John | Doe | [email protected] | basic | - |
---------------------------------------------------------------------------
| 23 | Peter | Miller | [email protected] | advance | basic |
---------------------------------------------------------------------------
我嘗試連接到這一點下面::
SELECT
candidates.firstname,
candidates.surname,
candidates_language.candidates_id,
candidates_language.skill,
languages.languageID
FROM
candidates,
candidates_language,
languages
不幸的是我只是遠離實際結果我想要的代碼。有沒有機會可以幫助我呢?
你想爲你的語言表中的每個可用語言添加一列嗎?還是隻想爲特定語言添加列? – RavB
嗨RavB, 我只需要特定語言的列.btw在你的筆記上編輯我的問題庫 – Andurit