sql >> Base de Datos >  >> RDS >> Sqlserver

Combinar dos tablas/concatenar valores en una sola columna

Creo que esto lo hará:

SELECT parent_id AS ID, 
  STUFF((
    SELECT ','+color FROM TableB a WHERE a.parent_id = b.parent_id FOR XML PATH('')
  ),1,1,'') AS color,
  STUFF((
    SELECT ','+Location FROM TableB a WHERE a.parent_id = b.parent_id FOR XML PATH('')
  ),1,1,'') AS Location,
FROM TableB b
GROUP BY parent_id