Ошибка MySQL 1054: неизвестный столбец 'hotels.postal_code' в 'on clause'

Я не слишком уверен, почему, но мои коды не могут работать. Я получаю ошибку 1052 или 1054. Вот мои коды. Пожалуйста помоги.

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

2 ответа

Решение

Замещать

FROM
malls

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id

КАК

FROM
malls

        join
    hotel_sales ON malls.postal_code = hotel_sales.sales_id

присоединение MALLS а также HOTEL_SALES с правой колонкой...

Таким образом, последний запрос будет..

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 malls.postal_code = hotel_sales.sales_id
        join
    postal_code_location ON hotels.district = postal_code_location.district

Эта ошибка о

Устранение неоднозначности column_id в вашем запросе

Должно быть как то так

SELECT
    hotels.postal_code AS ' Hotel Postal Code',
    hotels.name AS 'Hotel Name',
    hotels.latitude AS 'Latitude',
....
Другие вопросы по тегам