

I know the way to merge field in
- MySQL: CONCAT( )
- Oracle: CONCAT( ),||
- SQL Server: `+
but... I wanna merge AFTER query, is it possible?


I know the way to merge field in
CONCAT( )CONCAT( ), ||but... I wanna merge AFTER query, is it possible?
 
    
     
    
    Here you go:
MySQL using group_concat:
select a.name,
    a.opcode,
    group_concat(month order by b.pk separator ', ') as months
from tablea a
join tableb b on a.opcode = b.opcode
group by a.name, a.opcode;
Oracle using listagg:
select a.name,
    a.opcode,
    listagg(month,', ') within group (order by b.pk) as months
from tablea a
join tableb b on a.opcode = b.opcode
group by a.name, a.opcode;
SQL Server using for xml path and stuff:
select a.*,
    stuff((
        select ', ' + month from tableb b
        where a.opcode = b.opcode
        order by pk 
        for xml path(''), type
        ).value('(./text())[1]', 'varchar(max)')
    , 1, 2, '') as months
from tablea a;
