Hi SK RAFI,
One of the way to do it using OLAP function.
Following query would help you to understand the same.
May be you can write a recursive or stored procedure to meet your requirements on top of it.
SEL
t.id,
MAX( (CASE WHEN t1.rnk =1 THEN t1.name END) )
|| TRIM(CAST(',' AS CHAR(1))) ||
MAX( (CASE WHEN t1.rnk =2 THEN t1.name END) )
AS concat_name
FROM
tab1 t
INNER JOIN
(SEL
id
,name
, RANK () OVER (PARTITION BY id ORDER BY name) rnk
FROM tab1
) t1
ON t.id = t1.id
GROUP BY 1
Regards
Hi SK RAFI,
One of the way to do it using OLAP function.
Following query would help you to understand the same.
May be you can write a recursive or stored procedure to meet your requirements on top of it.
SEL
t.id,
MAX( (CASE WHEN t1.rnk =1 THEN t1.name END) )
|| TRIM(CAST(',' AS CHAR(1))) ||
MAX( (CASE WHEN t1.rnk =2 THEN t1.name END) )
AS concat_name
FROM
tab1 t
INNER JOIN
(SEL
id
,name
, RANK () OVER (PARTITION BY id ORDER BY name) rnk
FROM tab1
) t1
ON t.id = t1.id
GROUP BY 1
Regards