SELECT multiple rows from single column into single row

后端 未结 3 1343
傲寒
傲寒 2021-01-03 13:25

I want to write an SQL Server query that will retrieve data from the following example tables:

Table: Person
ID      Name
--      ----
1       Bill
2       B         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 13:45

    What you are looking for is something like SQL Server's FOR XML PATH('') which combines results as a rowset

    Select Person.Name, 
      (
         Select SkillName + ',' 
         From SkillLink 
         inner join skill on skill.id = skilllink.skillid
         Where SkillLink.PersonID = Person.ID FOR XML PATH('')
      )
    as Skills
    FROM Person 
    

提交回复
热议问题