Tricky CONCAT statement

I got stuck with this statement.

I have two tables:

Author: author_id, author_name
Wrote: book_id, author id

I want to get book_id with all its authors in one field, concatenating all the authors’ names.

For instance, let’s suppose we have

Wrote:
book_id author_id
10 50
10 51
10 52

Author:
author_id author_name
50 John
51 Mike
52 Lisa

I want to make a select statement which brings:

book_id Authors
10 John, Mike, Lisa

Please HELP!!!

use the GROUP_CONCAT function

Putting r937’s suggestion into a query, you get:


SELECT w.book_id, GROUP_CONCAT(a.author_name) AS authors
FROM Wrote AS w
INNER JOIN Author AS a ON w.author_id = a.author_id
GROUP BY w.book_id;