Tuesday 15 June 2010

oracle - Concatenate multiple rows into single column where data coming from multiple tables -



oracle - Concatenate multiple rows into single column where data coming from multiple tables -

i have info coming different tables there multiple rows of info in column want concatenate 1 column. this

select a.column1, b.column1, a.column3, c.column1, c.column4, d.column1 tablea a, tableb b, tablec c, tabled d a.id=b.id , b.id=c.id , a.code=d.code

the output

1 name table c info table d info 1 name b table c info table d info 1 name c table c info table d info 2 name d table c info table d info 2 name table c info table d info 2 name r table c info table d info 3 name f table c info table d info 4 name f table c info table d info 4 name e table c info table d info 4 name d table c info table d info 4 name c table c info table d info

except column b else repeating since column b having different data. want concatenate names 1 column don't other columns repetitive. tried using listagg function says not single-group function first row. please guide me how acheive this. want output

1 name a,name b name c table c info table d info 2 name d,name a, name r table c info table d info 3 name f table c info table d info 4 name f,name e,name d,name c table c info table d info

thanks in advance

this should work think

select a.column1,listagg(b.column1,',') within grouping (order b.column1), a.column3, c.column1, c.column4, d.column1 tablea a, tableb b, tablec c, tabled d a.id=b.id , b.id=c.id , a.code=d.code grouping a.column1, a.column3, c.column1, c.column4, d.column1;

oracle oracle11g

No comments:

Post a Comment