Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE libro( > id_libro INT PRIMARY KEY AUTO_INCREMENT, > titulo VARCHAR(20) > ); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE autor( > id_autor INT PRIMARY KEY AUTO_INCREMENT, > autor VARCHAR(20) > ); > > <pre> > ✓ > </pre> <!-- --> > CREATE TABLE autores( > id INT PRIMARY KEY AUTO_INCREMENT, > id_libro INT NOT NULL, > id_autor INT NOT NULL > ); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO libro(titulo) > VALUES > ("oro"), > ("plata"), > ("bronce"), > ("diamante"); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO autor(autor) > VALUES > ("pedro"), > ("daniel"), > ("luis"), > ("alfredo"); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO autores(id_libro, id_autor) > VALUES > (1, 2), > (1, 2), > (1, 3), > (1, 4), > (2, 1), > (2, 2), > (2, 3), > (2, 4), > (3, 1), > (3, 2), > (3, 3), > (3, 4), > (4, 1), > (4, 2), > (4, 3), > (4, 4); > > <pre> > ✓ > </pre> <!-- --> > SELECT libro.id_libro, libro.titulo, GROUP_CONCAT(autor.autor) AS Autores > FROM libro > JOIN autores ON libro.id_libro = autores.id_libro > JOIN autor ON autor.id_autor = autores.id_autor > GROUP BY libro.id_libro, libro.titulo; > > <pre> > id_libro | titulo | Autores > -------: | :------- | :------------------------- > 1 | oro | daniel,alfredo,luis,daniel > 2 | plata | daniel,pedro,alfredo,luis > 3 | bronce | luis,daniel,pedro,alfredo > 4 | diamante | alfredo,luis,daniel,pedro > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=c07155b90f67096f8fedda696629c41f)*
back to fiddle