I am creating a small database to store the books I own at home, but I came across the following situation: I have two associative tables, one called book_manager , which allows a same book has several authors and a genre_library call, which allows a given book to be part of one or more genres (two, to be exact). My problem is when it comes to creating a SELECT that brings information from books (for example: authors, page qtd), but also bring which genres this book is part of. I was able to create the query, but my code is repeating the authors and the genres of the books several times. What is causing this repetition?
Follow my code (I'm using MYSQL):
SELECT group_concat(a.nome) as 'Autores', l.titulo as 'Título', l.pag as 'Páginas', group_concat(g.tipo), e.nome as 'Editora'
FROM autor_livro al
INNER JOIN autor a ON a.id_autor = al.autor
INNER JOIN livro l ON l.id_livro = al.livro
INNER JOIN editora e ON e.id_editora = l.editora
INNER JOIN genero_livro gl ON gl.livro = al.livro
INNER JOIN genero g ON g.id_genero = gl.genero
GROUP BY al.livro;