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.

2

2 Answers 2

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

see SqlFiddle

Sign up to request clarification or add additional context in comments.

Comments

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?


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.