1

I have executions and each execution has several images, example,

table execution

 id |    name
 1   execution1

table image

id |   executionId | image
1          1          'path'
2          1          'path2'

I want a query that get all the executions, with each execution having all their images like,

  { executions: [
         { id: 1,
           name: execution1,
           images: 'path+path2'
          },
         {...}
      ]
 }

1 Answer 1

2

you could try using a group_concat

     select a.name, group_concat(image.image SEPARATOR '+')
     from execution a 
     left join image on image.executionId = a.id
     group by  a.name
Sign up to request clarification or add additional context in comments.

2 Comments

You can change to whatever you prefer. But imho this way it will return records even when there is no related data in image table with empty/null value for grouped column, which I would prefer to have if I would develop any application. But that is you answer, you just had no join (typo I guess) at all. Sorry if that disturb you from any point.
@Alex You don't disturd .. .. each time someone edit an aswer for a better version is good. my comment was for ask if there was somethings i haven't see in question ,... i look only at sample provided . without moral o etichal (good code / bad code ) evaluation of the code provided by OP. r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.