SELECT people.first_name AS "First Name", people.last_name AS "Last Name", countries.name AS "Country1", territories.name AS "Territory1", cities.name AS "City1", countries.name AS "Country2", territories.name AS "Territory2", cities.name AS "City2"
FROM adb_people AS people
JOIN root_cities AS cities ON people.city1 = cities.id
AND people.city2 = cities.id
JOIN root_territories AS territories ON people.prov_state1 = territories.id
AND people.prov_state2 = territories.id
JOIN root_countries AS countries ON people.country1 = countries.id
我在這裏要做的是將Country1(id)鏈接到Country1(名稱),並只顯示名稱。 此代碼示例僅適用於如果Country1,Territory1,City1與Country2,Territory2,City2相同MySQL在同一個表上連接多個連接?
我想象我的問題是我如何做我的JOIN。我是新來的東西的SQL方面。我已經在互聯網上閱讀了JOINS(谷歌搜索和閱讀前幾個教程),但是我沒有看到任何幫助。
我真的很感謝任何幫助,我在這裏做錯了。也許在正確的方向推動?
呃,我爲什麼不試試這個開頭。我現在將執行它並讓你知道它是如何發生的。謝謝! – rlemon
這個答案還沒有問題,它只適用於city1 = city2嗎? –
它不應該,不。我只是編輯查詢,因爲我忘了在複製/粘貼的選擇部分中更改我的表別名,如果這是你所指的? –