您好我正在尝试编写查询以获取有关作者,标题,类别和媒介的信息。 但是由于项目可以在许多媒介和类别中,我得到的结果在列中重复出现。我怎样才能得到结果,所以我看不到像恐怖,幻想,小说这样的书籍,书籍,书籍和类别。我假设我需要某种子查询 - 如果是这样我将如何做?
SELECT book.bookid, book.author, book.title, group_concat(category.categorydesc), group_concat(medium.mediumdesc)
FROM book
Inner JOIN bookscategories ON book.bookid = bookscategories.bookid
Inner JOIN category ON bookscategories.categoryid = category.categoryid
Inner JOIN booksmediums ON book.bookid = booksmediums.bookid
Inner JOIN medium ON booksmediums.mediumid = medium.mediumid
GROUP BY book.bookid
由于 汤姆
答案 0 :(得分:3)
正如评论中所述,解决方案是在GROUP_CONCAT()指令中添加DISTINCT关键字:
... book.title, group_concat(DISTINCT category.categorydesc), group_concat(DISTINCT medium.mediumdesc) ...