There is the following database schema
Please tell me how on the server side to glue the performers of the application for the given scheme?
What I tried to do myself:
SELECT r.Id AS RequestId, r.OpeningDate, rh.Note FROM Requests r INNER JOIN (SELECT * FROM RequestHistories rh WHERE rh.Id IN (SELECT MAX(_rh.Id) AS Id FROM RequestHistories _rh GROUP BY _rh.RequestId)) rh ON r.Id = rh.RequestId INNER JOIN RequestHistoryPerformers rhp ON rh.Id = rhp.RequestHistoryId WHERE r.ClosingDate IS NULL With this query, I start to collect the presentation I need, but I cannot understand how to add the LastName from the Performers table to the resulting query through the separator, i.e. get something like Ivanov, Petrov
Tried to do with for xml path :
Select r.Id as RequestId , r.OpeningDate , (select _p.LastName + ',' from performers _p where _p.Id=rhp.PerformerId for xml path('')) as Performers but unfortunately could not achieve the desired result
