MySql - 创建视图时遇到问题
Posted
技术标签:
【中文标题】MySql - 创建视图时遇到问题【英文标题】:MySql - Trouble Creating View 【发布时间】:2013-03-15 00:20:08 【问题描述】:尝试在 mysql 中创建视图时收到此消息。我也尝试为每一列赋予别名,但仍然收到错误消息。怎么回事!?提前致谢。
错误信息
错误 1060:列名“ID”重复
代码
CREATE VIEW contactnotes AS
SELECT contact.ID, log.ID, contact.Name, log.notes
FROM log
JOIN contact
ON log.ID = contact.ID
别名尝试
CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log
JOIN contact
ON id1 = id2
【问题讨论】:
【参考方案1】:CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log
JOIN contact
ON log.ID = contact.ID
或
CREATE VIEW contactnotes AS
SELECT contact.ID as id1, log.ID as id2, contact.Name, log.notes
FROM log
INNER JOIN contact USING (ID)
【讨论】:
以上是关于MySql - 创建视图时遇到问题的主要内容,如果未能解决你的问题,请参考以下文章
创建mysql视图时是不是应该在SELECT语句中引用多个表?