0

I have a query which gets all public transport subscriptions. A subscription can have multiple related companies. So I wanted to do with my query is to get all the subscriptions and instead of creating a row each time I have a related company, the companies should by group into one column. Is it possible to do that?

Here's the query :

SELECT pts.Id_PublicTransportSubscription, 
       pts.Amount, 
       ptc.Name
FROM bm_PublicTransportSubscriptions AS pts 
  INNER JOIN bm_PublicTransportSubscriptionByCompany AS ptsbc 
  ON pts.Id_PublicTransportSubscription = ptsbc.Id_PublicTransportSubscription 
  INNER JOIN bm_PublicTransportCompanies AS ptc 
  ON ptsbc.Id_PublicTransportCompany = ptc.Id_PublicTransportCompany

I'm using SQL Server 2008.

Nikola Markovinović
  • 18,963
  • 5
  • 46
  • 51
Traffy
  • 2,803
  • 15
  • 52
  • 78

1 Answers1

0

You can use the GROUP_CONCAT aggregate function.

linepogl
  • 9,147
  • 4
  • 34
  • 45