I have this query:
SELECT Id,
SUBSTRING(
(SELECT ',' + lts.Selection
FROM LiveTrainingSelections lts
INNER JOIN LiveTraining lt ON lt.Id = lts.LiveTrainingId
WHERE lts.SelectionType = 'Session Format' and lts.LiveTrainingId = lt.Id
FOR XML PATH('')),2,200000) AS SelectionDetails
FROM LiveTraining lt
JOIN LiveTrainingSelections lts
ON lt.Id = lts.LiveTrainingId
This is working almost properly, the only thing is that I'm getting all the records concatenated in one field, but I want to get all the fields specific for that Id, please check the screenshot
As you can see in the first result all the values are concatenated and the LiveTrainingId is ignored, but what I want to get is only the three values specific for that LiveTrainingId concatenated.