Skip to content
Advertisement

SQL Server Concatenate three different columns into a Comma-Separated without repeated values

The next table is a simplification of my problem in SQL Server:

I want to get a group with the columns concatenated by comma without repeated values. I tried to use STRING_AGG() but it returns:

This is the query I have done:

I would like the next result:

Thank you!

Advertisement

Answer

Without using window functions. The union might slow things down, but give it a try and see if you can tolerate the performance.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement