Merge two tables / concatenate values into single column

后端 未结 3 1181
执笔经年
执笔经年 2021-01-01 07:46

I have two tables: table A holds master product data, and table B holds children product data. I would like to update table A to hold the same value of the identical column

3条回答
  •  無奈伤痛
    2021-01-01 08:26

    I think this will do it:

    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
    

提交回复
热议问题