简体   繁体   English

MySQL错误1054:'on子句'中的未知列'hotels.postal_code'

[英]MySQL Error 1054: Unknown Column 'hotels.postal_code' in 'on clause'

I'm not too sure why but my codes can't seem to work. 我不太清楚为什么,但我的代码似乎无法正常工作。 Its either I get Error 1052 or 1054. Here are my codes. 它要么我得到错误1052或1054.这是我的代码。 Please Help. 请帮忙。

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

Replace 更换

FROM
malls

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id

AS

FROM
malls

        join
    hotel_sales ON malls.postal_code = hotel_sales.sales_id

Joining MALLS and HOTEL_SALES with right column... 使用右栏加入MALLSHOTEL_SALES ......

So the final Query would be.. 所以最终的查询将是......

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

This error is about 这个错误是关于

Disambiguate column_id in your Query 在您的查询中消除列column column_id的歧义

It should be something like this 它应该是这样的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM