Duplicate of question How to use GROUP BY to concatenate strings in SQL Server?
I have a table where I want to perform a similar groupby as illustrated with pandas. So for each group find the unique values of the relevant column and (assuming it is a string) concatenate them into one string seperated by comma. How can such a query be performed in SQL?
>>> import pandas as pd
>>> raw_table = pd.DataFrame(data = {'key1':[1,2,1,2,1,3,1],'key2':['a','b','c','a','b','c','a']})
>>> raw_table.groupby('key1').key2.apply(lambda x:",".join(set(x)))
key1
1 a,c,b
2 a,b
3 c
Name: key2, dtype: object