MySQL创建视图问题,
我使用一个视图作为表来连接 3 个表上的数据:
create view category_list as
select forum_categories.*, max( forum_answer.a_id ) as latest_answer_id
from forum_categories
left join forum_question on forum_question.catid = forum_categories.id
left join forum_answer on forum_answer.question_id = forum_question.id
and forum_answer.qtitle = forum_question.topic;
但是,我遇到了两个问题:
- 仅从 forum_categories 中提取一条记录进行链接
- 我无法将 forum_answer.qtitle 与 forum_question.topic 相关联
,请告知:)
谢谢。
I'm using a view as a table to join data on 3 tables:
create view category_list as
select forum_categories.*, max( forum_answer.a_id ) as latest_answer_id
from forum_categories
left join forum_question on forum_question.catid = forum_categories.id
left join forum_answer on forum_answer.question_id = forum_question.id
and forum_answer.qtitle = forum_question.topic;
However, I am experiencing two problems:
- Only one record from forum_categories is pulled out to be linked with
- I am unable to associate forum_answer.qtitle with forum_question.topic
please advise :)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缺少 group by 子句。 这是我整理的一个非常简单的示例,下面是我用来创建简单测试数据的 sql。
The group by clause is missing. Here's a very simple example I put together, and below it the sql I used to create the simple test data.