How to show records of 2 related tables?

1

I have a CRUD with multiple files, create 2 tables, one is an activity where all the data goes and another image where only the files associated with the activity go.

The problem happens that if user wants to add 2 or more files to the activity, at the moment of showing the data in table, the same number of files will be repeated. occupy this simple query

SELECT a.nombre, a.descripcion, a.objetivo, a.cursos, a.seccion, a.codigo, a.fecha, a.comuna, a.numero_estudiantes, a.socio , i.file
FROM actividad a
INNER JOIN imagen i ON i.id_actividad_imagen = a.id_actividad

I want to show it is that in the file register I see the 2 images together 223526_10200626375121015_1296632947_n.jpg, images.png.

    
asked by claudia24 01.06.2018 в 01:44
source

1 answer

1

Try it with GROUP_CONCAT like this:

SELECT a.nombre, a.descripcion, a.objetivo, a.cursos, a.seccion, a.codigo, a.fecha,
       a.comuna, a.numero_estudiantes, a.socio , GROUP_CONCAT(i.file SEPARATOR ',')
FROM actividad a
INNER JOIN imagen i ON i.id_actividad_imagen = a.id_actividad
GROUP BY a.nombre, a.descripcion, a.objetivo, a.cursos, a.seccion, a.codigo, a.fecha, 
         a.comuna, a.numero_estudiantes, a.socio
    
answered by 01.06.2018 / 01:57
source