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 (name)에 연결하고 이름 만 표시하려고합니다. 이 코드 예제는 Country1, Territory1, City1이 Country2, Territory2, City2와 동일한 경우에만 작동합니다.같은 테이블에 MySQL 조인 여러 조인?
나는 내 JOIN을 어떻게 수행하고 있는지 이미지로 나타낼 것입니다. 나는 사물의 SQL 측면에 익숙하지 않다. 나는 인터넷 (Google 검색 및 처음 몇 자습서를 읽음)에서 JOINS를 읽었지만 읽지 않은 것은이 경우에 도움이되었습니다.
내가 여기서 잘못하고있는 것에 대해 도움을 주시면 감사하겠습니다. 어쩌면 올바른 방향으로 움직일 수 있을까요?
어째서 나는 그렇게하려고하지 않았는가? 나는 그것을 지금 구현하고 어떻게 진행되는지 알려줄 것이다. 고맙습니다! – rlemon
이 답변은 city1 = city2 인 경우에만 작동하는 문제가 여전히 있습니까? –
안된다. 그게 당신이 말하는 거라면 복사/붙여 넣기에서 선택 부분에 내 테이블 별칭을 변경하는 것을 잊었 기 때문에 나는 단지 쿼리를 편집 했나요? –