join - MySQL: get records from database and add a COUNT() column to the rows -
I am trying to retrieve books from a table and left to join in the table of chapters . From the second table, what I need is to add only COUNT () of the available chapters for those books and that value as an additional column named Chapter (or something).
My current endeavor looks like this: SELECT B. *, Include chapter B as c. Chapters from chapter (c.chapter_nr) as books
As C_book_id = b.id
it only becomes one, the table of books and the count () results in that row, but I want to get all the rows from the table of books, Therefore the left pair
SELECT b. *, B as the chapter from books in the form of counts (c.chapter_nr) B. LEFT JOIN CHAPTER C (c.book_id = b.id) Group B. ID
explanation
To determine the actual chapter calculations, you need a group according to the book If you wanted to leave the group by clause, Will receive a result of all chapters. You want to limit the results to unique books and related chapter calculations
Comments
Post a Comment