2014-02-10 6 views
1

이유는 모르지만 코드가 작동하지 않는 것 같습니다. 그 중 하나는 오류 1052 또는 1054가 나타납니다. 여기에 내 코드가 있습니다. 도와주세요.MySQL 오류 1054 : 알 수없는 열 'on clause'의 'hotels.postal_code'

SELECT 

    hotels.postal_code AS ' Hotel Postal Code', 
    name AS 'Hotel Name', 
    latitude AS 'Latitude', 
    longitude AS 'Longitude', 
    address AS 'Hotel Address', 
    hyperlink AS 'Hotel Hyperlink', 
    hotels.district AS 'Hotel District', 
    'hotel' AS type 

FROM 
    hotels 

     join 
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id 
     join 
    postal_code_location ON hotels.district = postal_code_location.district 

UNION SELECT 

    malls.postal_code AS ' Mall Postal Code', 
    name AS 'Mall Name', 
    latitude AS 'Latitude', 
    longitude AS 'Longitude', 
    address AS 'Mall Address', 
    hyperlink AS 'Mall Hyperlink', 
    malls.district AS 'Mall District', 
    'mall' AS type 
FROM 
malls 

     join 
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id 
     join 
    postal_code_location ON hotels.district = postal_code_location.district 
+1

과 같이해야한다

쿼리에 대한

명확의 COLUMN_ID? – Mureinik

+0

'ON hotels.postal_code = hotel_sales.sales_id '가 잘못되었습니다. 'ON hotels.hotel_id = hotel_sales.hotel_id' 인 것처럼 나에게 들리는가요? –

+0

두 번째 선택에서는'hotels.postal_code'에 참여하고 있지만'hotels'은 해당 쿼리에 사용되지 않습니다. 당신은'몰'중에서 선택합니다. –

답변

2

교체

FROM 
malls 

     join 
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id 

..

그래서 최종 쿼리가 될 것 ... MALLS과 오른쪽 열이 HOTEL_SALES 가입

FROM 
malls 

     join 
    hotel_sales ON malls.postal_code = hotel_sales.sales_id 

AS

+0

다시 "작동하지 않습니다"전에 실제로 hotels.district도 편집하고 싶습니다. – oerkelens

+0

괜찮은 문제가 해결되었습니다. :) 모두들 고마워요! – iRandallT

1

이 오류는 당신이 당신의 테이블의 DDLs를 공유 할 수이

SELECT 
    hotels.postal_code AS ' Hotel Postal Code', 
    hotels.name AS 'Hotel Name', 
    hotels.latitude AS 'Latitude', 
....