Consider a table as follows -
TABLE DB.TEMP_TABLE
------------------------------------------
field1 field2 field3
------------------------------------------
1 10 100
1 20 200
1 30 300
1 40 400
2 10 100
2 20 200
I need to concatenate field2
and field3
on the basis of field1
. The desired result should look like this -
DESIRED RESULT
------------------------------------------
field1 field2 field3
------------------------------------------
1 10,20,30,40 100,200,300,400
2 10,20 100,200
The query I am using for this query is given below -
SELECT field1,
wm_concat(field2),
wm_concat(field3)
FROM temp_table
GROUP BY field1;
Here is the result I am getting -
------------------------------------------
field1 field2 field3
------------------------------------------
1 10,20,40,30 100,400,300,200
2 10,20 100,200
Please suggest me a working query and if possible please explain this behaviour.
I am using Oracle 10g
and have also tried using xmlagg
.