0

I have three tables as shown below.

How to get comma separated output from joining these three table? Desired output is also shown here. By searching I found joining of two tables only.

Table1

staff_id   vehicle_id
---------------------
1           22
1           33
1           44
2           55

Table2

  vehicle_id   vehicle_type_id
  ----------------------------    
      22         1000
      33         1000
      44         3000
      55         2000
      65         2000
      75         2000

Table3

    vehicle_type_id  vehicle_type_name
    ----------------------------------
         1000               AA
         2000               BB
         3000               CC
         4000               DD
  

Desired output:

staff_id   vehicle_type_name
----------------------------
1                AA,AA,CC
2                 BB
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2431727
  • 877
  • 2
  • 15
  • 46
  • Which SQL Server version? – jarlh Mar 22 '22 at 09:48
  • This post should help: [sql - Optimal way to concatenate/aggregate strings](https://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings) and [How to concatenate text from multiple rows into a single text string in SQL Server](https://stackoverflow.com/questions/194852/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-serv/3672860#3672860) – DocZerø Mar 22 '22 at 09:51
  • 2
    As a side not, SQL Server 2008 is now completely unsupported, and has been for almost 2 years, @user2431727 . You should really be looking into an upgrade path. If you were on a supported version of SQL Server, you'd find this much easier. – Thom A Mar 22 '22 at 10:06
  • @Larnu Sorry I'm using Microsoft SQL Server 2014 – user2431727 Mar 22 '22 at 10:37

0 Answers0