How to limit values when using distinct

前端 未结 4 1927
暗喜
暗喜 2021-01-22 10:30

PHP

  SELECT DISTINCT bk.title AS Title, bk.year AS Year, aut.authorname AS Author, cat.category AS Category
         FROM book bk 

         JOIN book_category          


        
4条回答
  •  后悔当初
    2021-01-22 10:37

      SELECT DISTINCT bk.title AS Title, bk.year AS Year, aut.autName AS Author, cat.category AS Category
         FROM book bk 
    
         JOIN book_category bk_cat 
         ON bk_cat.book_id = bk.bookid
    
         JOIN categories cat 
         ON cat.id = bk_cat.category_id
    
    
         JOIN (SELECT GROUP_CONCAT(aut.authorname) as autName FROM authors JOIN books_authors ON books_authors.author_id=authors.author_id WHERE books_authors.book_id=bk.bookid) as aut
    
    
         ORDER BY bk.title ASC
    

提交回复
热议问题