Outputting mySQL Result with data from one column grouped into a single cell

mysql

Solution

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

Problem

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 ``` that returns the following sample result: ``` workID team_ID teamName 1 10 Support 2 20 Dev 2 10 Support 3 30 Admin 4 40 Research ``` And I want to output it to the screen in a table format so that there is a row per workID, and column that has a list of team names. Something like: ``` WORK ID | TEAM NAME ------------------------- 1 | Support 2 | Dev | Support 3 | Admin 4 | Research ``` I know a query in a query is not the right way (even though it is the easiest). I have seen some stuff on nested arrays but as a newbie I am not really clear on how to do it. Anyone want to devote some time to talking me off the ledge? Thanks...

Original source