0

I have an SQL (Oracle Solution) output which looks like below:

ID        Value
1         31 
1         44
2         31
3         22  
4         57  
4         69  

ID and value are brought in from different tables using an inner join.

When I select ID and Value, I am wanting to concatenate the value (separated by a comma) when the ID is a match, so that it looks like below:

ID        Value
1         31,44 
2         31
3         22  
4         57,69 

How can I make this happen?

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • 1
    Which database are you using and have you tried something yet? – Tim Biegeleisen Aug 15 '17 at 05:47
  • The correct answer to this question is DBMS specific. Oracle solution will not work in Sql Server, while Sql Server vNext solution will not work on older versions of Sql Server. If you want to get a correct answer, [edit] your question to include the relevant rdbms tag (product and version). – Zohar Peled Aug 15 '17 at 05:54
  • Wrong duplicate. This question is about oracle, not SQL server. – Zohar Peled Aug 15 '17 at 06:10
  • You would need this: `SELECT ID, LISTAGG(Value, ',') within group (order by ID) from (the query from different tables using an inner join) Group By ID;`. Try that one and let me know. – g00dy Aug 15 '17 at 06:23
  • Yep, that did it. Thanks! – kingduckman Aug 16 '17 at 00:06

0 Answers0