K
K
Kolya Vantukh2017-03-18 20:27:58
MySQL
Kolya Vantukh, 2017-03-18 20:27:58

Why doesn't GROUP_CONCAT work?

There is a query that selects books and authors for them. There are 3 tables: books, authors, authors_books
It is necessary that all authors associated with it be displayed next to the book.

$sql = "SELECT b.*,a.name,a.surname, GROUP_CONCAT(a.surname) as surname FROM books b"
                . " INNER JOIN authors_books ab on b.id = ab.book_id"
                . " LEFT  JOIN authors a on ab.author_id = a.id";

But with such a request, absolutely all the author is displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2017-03-18
@vkolya

We look at examples of group_concat in any description and pay attention to the presence of group by there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question