Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to concatenate two columns value in to a single column based on it's id.
So i have tried the bellow code -

JavaScript
RTRIM(XMLAGG(XMLELEMENT(E,EMP_NAME,', ').EXTRACT
('//text()')
  ORDER BY EMP_NAME).GetClobVal(),',') EMP_NAME


But it is showing the data multiple times. Please suggest a way to resolve it.

Example - table name EMP having columns -(EMP_ID, EMP_NAME) values - ('1', 'Sourav Ganguly'),('1', 'Sachin Tendulkar'). The table is not having such a column as primary key.

expected Output -

EMP_NAME

Sourav Ganguly, Sachin Tendulkar - in a single row.

But Output is coming as -

EMP_NAME

Sourav Ganguly, Sourav Ganguly, Sourav Ganguly, Sourav Ganguly, Sourav Ganguly, Sachin Tendulkar,Sachin Tendulkar, Sachin Tendulkar, Sachin Tendulkar, Sachin Tendulkar.


Please help me to avoid the duplicacy.

Thanks in Advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900