gpt4 book ai didi

mysql - SQL : a set of results inside each result

转载 作者:行者123 更新时间:2023-11-29 01:48:43 26 4
gpt4 key购买 nike

我有一个表articles,它的结构如下:

id, name, date, contents

我有一个表authors,它的结构如下:

id, article_id, name, email

一篇文章可以有很多作者。

如何获取文章列表,每行显示该文章的多个作者(几乎就像每个文章行中的一组结果)

我觉得用 SQL 做这件事很简单,但我不知道要查找的正确术语。我一直在搜索整个下午都无济于事。谁能帮忙?

最佳答案

您可以使用以下解决方案使用 GROUP_CONCAT :

SELECT articles.id, articles.name, GROUP_CONCAT(authors.name) AS authors
FROM articles LEFT JOIN authors ON articles.id = authors.article_id
GROUP BY articles.id, articles.name

demo on dbfiddle.uk

关于mysql - SQL : a set of results inside each result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56396874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com