我有以下SQL语句
SELECT articles.id, articles.title, tags.name AS tags
FROM articles
LEFT JOIN article_tag_association ON articles.id = article_tag_association.article_id
LEFT JOIN tags ON tags.id = article_tag_association.tag_id
这个方法可以正常工作,但是对于每个标签,它都会创建一行,这会影响限制。例如:
[
"0" => ["id" => "1", "title" => "test", "tags" => "tag1"],
"1" => ["id" => "1", "title" => "test", "tags" => "tag2"],
"2" => ["id" => "2", "title" => "test2", "tags" => "tag1"],
]
有没有办法使其返回每篇文章以及标签数组?
类似于:
[
"0" => ["id" => "1", "title" => "test", "tags" => ["tag1", "tag2"]],
"1" => ["id" => "2", "title" => "test2", "tags" => ["tag1"]],
]