2011-08-24 6 views
1

나는 쉼표 조인 대신에 조인을 사용하여 발생하는 문제를 해결하기 위해 노력해 왔습니다. 내 SQL은 현재 다음과 같습니다조인을 사용하면 열을 알 수 없음

실행되면
SELECT islandID AS parentIslandID, islandName, island.longDesc, 
imageLocation, COUNT(resort.resortID) AS totalResorts, resort.resortID 
FROM island, resort, images 
join resort as r1 
on island.islandID = resort.parentIslandID 
where 
r1.resortID IN ( 
59,62,65,69,71,72,74,75,76,82,86,89,91,93,95,105, 
106,116,117,118,120,121,122,123,124,125,126,127, 
131,145,146,150,157,159,160,167,170,174,176,185,188,189,193, 
194,198,199,200,203,205,213,217 
) 
&& resort.active = '-1' 
GROUP BY resort.parentIslandID 
ORDER BY totalResorts DESC 

, 나는 다음과 같은 오류 얻을 :

#1054 - Unknown column 'island.islandID' in 'on clause'

내가 몇 가지 조사를했고, 내가 해결하기 위해 노력했습니다 그러나 오류의 근원을 이해 "island"테이블에 대한 별칭을 만들어 문제를 해결하십시오. 이렇게하면 "island.longDesc"와 같은 열은 "알 수 없음"입니다.

누구든지 사소한 구문 문제 인 것처럼 보이는 부분을 고칠 수 있다면 크게 감사하겠습니다. 저는 쉼표 조인을 사용하는 데 더 익숙합니다. 덕분에 모든 도움말 -

-Aaron

편집을 위해 : 당신은 JOIN 구문의 두 가지 유형의 혼합되어

Images Structure: 
CREATE TABLE `images` (
    `imageID` int(11) NOT NULL auto_increment, 
    `imageType` int(11) NOT NULL COMMENT 'used to tell if its for an artist, header image, etc.', 
    `parentObjectID` int(11) NOT NULL COMMENT 'used to tell what island/resort the image applies to', 
    `imageLocation` text NOT NULL, 
    `largeImageLocation` text NOT NULL, 
    `imageLinkLabel` text NOT NULL, 
    `imageURL` text NOT NULL, 
    PRIMARY KEY (`imageID`) 
) 

Island Structure: 
CREATE TABLE `island` (
    `islandID` int(11) NOT NULL auto_increment, 
    `islandName` text NOT NULL, 
    `shortDesc` text NOT NULL, 
    `longDesc` text NOT NULL, 
    `getTo` text NOT NULL, 
    `getAround` text NOT NULL, 
    `photoInfo` text NOT NULL, 
    `flowerInfo` text NOT NULL, 
    `musicInfo` text NOT NULL, 
    `cakeInfo` text NOT NULL, 
    `activityInfo` text NOT NULL, 
    `wedCoord` text NOT NULL, 
    `regs` text NOT NULL, 
    `climate` text NOT NULL, 
    `languageID` int(11) NOT NULL, 
    `currencyID` int(11) NOT NULL, 
    `wideAccept` int(11) NOT NULL, 
    `passportReq` int(11) NOT NULL, 
    `picture` text NOT NULL, 
    `daysSearchable` int(11) NOT NULL, 
    `active` tinyint(1) NOT NULL, 
    PRIMARY KEY (`islandID`) 
) 

Resort Structure: 
CREATE TABLE `resort` (
    `resortID` int(11) NOT NULL auto_increment, 
    `resortName` text NOT NULL, 
    `parentIslandID` int(11) NOT NULL, 
    `longDesc` text NOT NULL, 
    `website` text NOT NULL, 
    `genBooking` text NOT NULL, 
    `eventCoord` text NOT NULL, 
    `amenInfo` text NOT NULL, 
    `roomInfo` text NOT NULL, 
    `coordInfo` text NOT NULL, 
    `localeInfo` text NOT NULL, 
    `spaInfo` text NOT NULL, 
    `roomPrice` text NOT NULL, 
    `maxGuests` text NOT NULL, 
    `picture` text NOT NULL, 
    `search_Inclusive` int(11) NOT NULL, 
    `search_resortType` int(11) NOT NULL, 
    `search_onBeach` int(11) NOT NULL, 
    `search_wedCoord` int(11) NOT NULL, 
    `search_roomRate` int(11) NOT NULL, 
    `search_airportDist` int(11) NOT NULL, 
    `search_HotelSuite` tinyint(1) NOT NULL, 
    `search_VillaCondo` tinyint(1) NOT NULL, 
    `search_Amenities` text NOT NULL, 
    `active` tinyint(1) NOT NULL, 
    PRIMARY KEY (`resortID`) 
) 
+0

우리는 t 그는 테이블에? –

+0

@BookOfZeus 구조가 원래 질문에 추가되었습니다. 엉망으로해서 미안해. – MingMing

답변

4

- 테이블이 FROM에 나와있는 암시 유형 및 명시 적 JOIN 유형입니다. 대신, 시도 :

SELECT 
    islandID AS parentIslandID, 
    islandName, 
    island.longDesc, 
    imageLocation, 
    COUNT(r1.resortID) AS totalResorts, 
    r1.resortID 
FROM island 
    JOIN resort r1 ON island.islandID = r1.parentIslandID 
    JOIN images ON island.islandID = images.parentObjectID 
WHERE 
    r1.resortID IN ( 
    59,62,65,69,71,72,74,75,76,82,86,89,91,93,95,105, 
    106,116,117,118,120,121,122,123,124,125,126,127, 
    131,145,146,150,157,159,160,167,170,174,176,185,188,189,193, 
    194,198,199,200,203,205,213,217 
) 
AND resort.active = '-1' 
GROUP BY r1.parentIslandID 
ORDER BY totalResorts DESC 

을 ** 테이블 구조 게시 한 후 섬 JOIN을 포함하도록 수정 됨.

는 또한 :

  • MySQL은 (JOIN resort r1)
  • 선택 목록에서 resort 별칭 r1를 사용하십시오 표 별칭이 AS 키워드가 필요하지 않습니다 AND보다는 && 부울 및
  • 를 사용 (r1.resortID)
+0

게시 한 코드를 실행했지만 여전히 오류 메시지가 나타납니다. 게시 된 SQL을 실행할 때 "알 수없는 열 'resort.resortID'필드 목록 '오류가 발생합니다. 어떤 아이디어? – MingMing

+0

@MingMing 어떤 오류가 있습니까? 또한 가장 최신 형태로 실행 했습니까? 게시 이후 몇 번 수정했습니다. –

+0

죄송합니다. 나는 주석을 제출 한 라인 리턴에 대해 ENTER를 계속 누르고있다. – MingMing

관련 문제