I try to accomplish the following:
I have two tables which are connected via a third table (N:N
relationship):
Table 1 "Locations"
LocationID (Primary Key)
Table 2 "Specialists"
SpecialistID (Primary Key)
Name (varchar)
Table 3 "SpecialistLocations"
SpecialistID (Foreign Key)
LocationID (Foreign Key)
(both together are the primary key for this table)
Issuing the following command
SELECT
L.LocationID , S.[Name]
FROM
Locations AS L
LEFT JOIN SpecialistLocations AS SL ON P.PlaceID = SL.LocationID
LEFT JOIN Specialists AS S ON SL.SpecialistID = S.SpecialistID
results in the following table:
LocationID | Name
1 Specialist 1
1 Specialist 2
2 Specialist 3
2 Specialist 4
3 Specialist 1
4 Specialist 4
Now my problem: I would like to have the following output:
LocationID | Names
1 Specialist 1, Specialist 2
2 Specialist 3, Specialist 4
3 Specialist 1
4 Specialist 4
....which is grouping by LocationID and concatenating the specialist
names.
Any idea on how to do this?
Thank you very much,
Dennis