开发者

Duplicate column names in SQL query

How do I avoid a dup column name error in MySQL when creating a VIEW on two tables that both have the same column name as shown here

CREATE VIEW db.VI_RegionCity AS SELECT
    Region.Name,
    City.Name
FROM
    db.Region Region,
    db.City City
WHERE
    Region.RegionCode = City.RegionCode



ERROR: Duplicate 开发者_高级运维column name 'Name'


Using alias for column name

CREATE VIEW db.VI_RegionCity AS SELECT
    Region.Name as Region_name,
    City.Name as City_name
...//rest of the query


CREATE VIEW db.VI_RegionCity AS SELECT
    Region.Name AS RegionName,
    City.Name AS CityName
FROM
    db.Region Region,
    db.City City
WHERE
    Region.RegionCode = City.RegionCode
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜