Table1 is like this
Id Name Subject
1 Rakesh English
1 Rakesh Maths
1 Rakesh Science
2 Mukesh English
2 Mukesh Maths
Table 2 which I want is like this:
Id Name Subject
1 Rakesh English, Maths, Science
2 Mukesh English, Maths
Table1 is like this
Id Name Subject
1 Rakesh English
1 Rakesh Maths
1 Rakesh Science
2 Mukesh English
2 Mukesh Maths
Table 2 which I want is like this:
Id Name Subject
1 Rakesh English, Maths, Science
2 Mukesh English, Maths
If you are using SQL 2017 or newer, you can use the STRING_AGG() function
select id, [name], string_agg(Subject,',') as [subject] from Table1 group by id, Name
18 People are following this question.