0

I'm trying to add a number of values into one, depending on a value coming from multiple different tables. I keep getting a syntax error. So I have the following table:

OT_ID CODE OPTION OPTION2
1 6T S34 A1C
1 6T Y78 Y08
1 6T S34 A1C
2 7Y Y78 YP8
2 7Y S34 A1C
2 7Y Y78 Y08

I want to combine the values in OPTION when the OT_ID is the same.

OT_ID CODE OPTION OPTION2
1 6T S34,Y78,S34 A1C,Y08,A1C
2 7Y Y78,S34,Y78 TP8,A1C,Y08

I have tried to following query:

SELECT t1.ot_id, t0.code, t2.option, t3.option2
  FROM test t0
  LEFT JOIN test1 t1
    ON t1.ot_id = t0.id
  LEFT JOIN optn t2
    ON t1.ot_id = t2_id
  LEFT JOIN addtopn t3    
    ON t1.ot_id = t3.id

I tried STING_AGG, but I'm getting a syntax error.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Lvh
  • 23
  • 3

0 Answers0