一尘不染

SQL查询中的列名称重复

sql

在两个具有相同列名的表上创建VIEW时,如何避免MySQL中的dup列名错误,如下所示

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'

阅读 144

收藏
2021-03-08

共1个答案

一尘不染

使用别名作为列名

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