0

I tried to display list of engineer names who work under the same project. Basically the first column or cell should have multiple EngineerName separated by , or spaces. In the second column is the ProjectID that is common between them. So the output should look like multiple rows of EngineerName lists and their common ProjectID is the second column.

I used this code and it only displayed single names for each project. Is there a way to display multiple names in one cell ?

SELECT e."EngineerName", w."ProjectID"
FROM public."Works_On" as w INNER JOIN public."Engineer" as e
ON w."EngineerID" = e."EngineerID"
GROUP BY e."EngineerName", w."ProjectID"
Luuk
  • 12,245
  • 5
  • 22
  • 33
Emerald
  • 3
  • 2
  • You can check this : https://stackoverflow.com/questions/2560946/postgresql-group-concat-equivalent – DB08 Mar 17 '22 at 17:33

1 Answers1

1

Try this, though have not tested:

SELECT w.ProjectID, 
       string_agg(e.EngineerName,',')
FROM public.Works_On as w 
INNER JOIN public.Engineer as e
ON w.EngineerID" = e.EngineerID
GROUP BY w.ProjectID
Stephan
  • 5,891
  • 1
  • 16
  • 24
DB08
  • 151
  • 6