Output mySQL result with data from one column grouped into one cell

I have a mySQL query:

SELECT work.ID AS workID ,team.ID AS team_ID ,team.name AS teamName FROM work LEFT OUTER JOIN team_work ON team_work.work_ID = work.ID LEFT OUTER JOIN team ON team_work.team_ID = team.ID 

which returns the following result:

 workID team_ID teamName 1 10 Support 2 20 Dev 2 10 Support 3 30 Admin 4 40 Research 

And I want to display it in a table format so that there is a row for each job identifier and a column with a list of command names. Sort of:

 WORK ID | TEAM NAME ------------------------- 1 | Support 2 | Dev | Support 3 | Admin 4 | Research 

I know that a query in a query is the wrong way (although this is the easiest). I saw some things on nested arrays, but as a beginner, I don't quite understand how to do this.

Does anyone want to devote time to me to talk to the counter?

Thanks...

+4
source share
1 answer
 SELECT work.ID AS workID ,group_concat(teamName) AS teamName FROM work LEFT OUTER JOIN team_work ON team_work.work_ID = work.ID LEFT OUTER JOIN team ON team_work.team_ID = team.ID group by work.ID 
+4
source

Source: https://habr.com/ru/post/1440830/


All Articles