Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Unisci due tabelle/concatena i valori in una singola colonna

Penso che questo lo farà:

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