MySQL query (select statement) question
Title Authors Categories Summary Article
----- ------- ---------- ------- -------
Title of article Author 1, Author 2 Cat 1, Cat 2, Cat 3 blablabla Lorum ipsum ...
thanx,
Pannix
3 Replies
SELECT a.Title AS Article,
GROUP_CONCAT(DISTINCT c.Category ORDER BY c.Category) AS Categories,
GROUP_CONCAT(DISTINCT CONCAT(b.FirstName, " ", b.LastName) ORDER BY b.LastName) AS Authors
FROM Articles AS a
LEFT JOIN ArticleCategories AS ac ON (a.ArticleID = ac.ArticleID)
LEFT JOIN Categories AS c ON (ac.CategoryID = c.CategoryID)
LEFT JOIN ArticleAuthors AS aa ON (a.ArticleID = aa.ArticleID)
LEFT JOIN Authors AS b ON (aa.AuthorID = b.AuthorID)
GROUP BY a.ArticleID;