mysql中的连接值,其中一个表中的多行与另一表中的一行相关
我有两个 mysql 表,一个列出文章名称,另一个列出与每篇文章相关的作者,如下所示:
article_id title
=======================
1 art1
2 art2
3 blob
article_id name surname
=====================================
1 jack smith
1 jill jones
1 rob edgar
2 billy bryce
3 dick bonsor
3 jeff kucick
我正在尝试创建一个将返回以下内容的查询:
article_id title author
=========================================================
1 art1 jack smith, jill jones, rob edgar
2 art2 billy bryce
3 blob dick bonsor, jeff kucick
我一直在查看 group_concat 和 concat_ws,但我一直在我尝试返回上述结果失败。如果你们对此有任何想法,我将不胜感激!
非常感谢。
I have two mysql tables, one listing article names, the other listing the authors associated with each article, as follows:
article_id title
=======================
1 art1
2 art2
3 blob
article_id name surname
=====================================
1 jack smith
1 jill jones
1 rob edgar
2 billy bryce
3 dick bonsor
3 jeff kucick
I am trying to create a query that will return the following:
article_id title author
=========================================================
1 art1 jack smith, jill jones, rob edgar
2 art2 billy bryce
3 blob dick bonsor, jeff kucick
I have been looking at group_concat and concat_ws, but I have been unsuccessful in my attempts to return the above result. If any of you have any thoughts on this, I would be most grateful!
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者,如果您想使用 concat_ws:
or, if you want to use concat_ws: