0

I would an example table as follows:

TableA

ID / Name / Sport

001 / Max / Football

005 / Steven / Badminton

006 / Cindy / Swimming

001 / Max / Tennis

001 / Max / Rugby

005 / Steven / Football

I would like a SQL query statement to return the result as follows:

ID / Name / SportList

001 / Max / Football; Tennis; Rugby

005 / Steven / Badminton; Football

006 / Cindy / Swimming

Sorry, I have to use '/' to differentiate the column. Unable to attached a file due to low reputation.

Thank you.

Milen
  • 8,697
  • 7
  • 43
  • 57

2 Answers2

2
select 
 Id,
 Name,
 GROUP_CONCAT(Sport  ORDER BY Sport SEPARATOR '; ')
FROM TableA
GROUP BY  Id, Name

see SqlFiddle

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122
0

There is no DB agnostic way to achieve this function.

How do I Create a Comma-Separated List using a SQL Query?

for Oracle:

Group_concat MySQL function's equivalent in Oracle

Is there any function in oracle similar to group_concat in mysql?


Community
  • 1
  • 1
RRM
  • 2,495
  • 29
  • 46