0

Possible Duplicate:
Is there an Oracle SQL query that aggregates multiple rows into one row?
Fast way to generate concatenated strings in Oracle

An oracle sql newbie question

i have a following table:

id1 A
id1 B
id1 C
id1 A
id2 A
id3 B
id3 A

What I want to get

id1 A,B,C
id2 A
id3 B,A

I cannot use loops, i have to get it with just a query

I use an Oracle DB v10 (I know it's important because of this).

Community
  • 1
  • 1

1 Answers1

0

You need to use wm_concat(fieldname) to solve the purpose. So your query will be :

SELECT attr1, wm_concat(attr2) FROM YourTable GROUP BY field2;

And If you want Duplicates to be removed then

SELECT attr1, wm_concat(distinct attr2) FROM YourTable GROUP BY field2;
djadmin
  • 1,742
  • 3
  • 19
  • 27