创建视图时出错代码:1060

时间:2014-11-20 01:06:49

标签: mysql create-view

我尝试创建视图,但我得到了重复的列名称' id'错误。它可以自己运行,但只要我创建了一个视图,它就无法工作。

create view question1_responders as select * from survey_responders join survey_responses on survey_responses.survey_responder_id = survey_responders.id where survey_question_id = 1 order by survey_responders.id

1 个答案:

答案 0 :(得分:0)

通过限定每个列名称,将您的CREATE VIEW语句更改为如下所示。错误主要是因为select *部分。指定要获取的特定列(OR)指定table_name.*

create view question1_responders as
select sr.* from survey_responders sr
    join survey_responses sres
    on sres.survey_responder_id = sr.id
    where sr.survey_question_id = 1
    order by sr.id