0

in MySQL data base, I have tow table like below :

gauges:

 id       data    comments   
 -------------------------------------
 1          x       someThing
 2          y       someThing
 4          z       someThing
 9          x       someThing

documantaries:

 id   status   gauge_id     docName    
 --------------------------------
 1     ok          1          x.png
 2     nok         1
 3     nok         1          
 4     ok          1          y.png
 5     ok          1          z.png
 6     nok         2          u.png
 7     nok         2          x.png
 8     ok          4          x.png
 9     ok          2          u.png
 10    ok          4          y.png

I need to select and join tables to find what is status in every row in first table according to second one. like this :

result

 id       data       status   
 -------------------------------------
 1          x       ok,nok,nok,ok,ok
 2          y       nok,nok,ok
 4          z       ok,ok
 9          x       

I think the link below is about my question but not exactly

Mysql Join results as single row

The code below is not working :

select gauges.*,documantaries.* join on gauges.id=documantaries.gauge_id ;
MrSalesi
  • 377
  • 3
  • 17

1 Answers1

1

You can se left join and group_concat():

select g.id, g.data,
       group_concat(d.status order by d.id) as statuses
from guages g left join
     documantaries d
     on d.gauge_id = g.id
group by g.id, g.data;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786