cancel
Showing results for 
Search instead for 
Did you mean: 

Concat Distinct rows into a single string

Former Member
0 Kudos

Hi,

In my table I have rows like this

Table Name : Test

Name

-----------------------

sam

khan

sun

sam

My query

Select string_agg(Name,',') from Test

Output

sam,khan,sun,sam

But it is giving Duplicate values like sam comes twice.

Please help me to Eliminate duplicates while using string_agg function

Accepted Solutions (0)

Answers (1)

Answers (1)

lbreddemann
Active Contributor
0 Kudos

You might be successful if you tell SAP HANA that you want the duplicates to be eliminated.

select string_agg_name,',') from

( select distinct name from test

)

You might be careful though when your inner select contains an aggregation already. Then the SAP HANA optimizer can find the DISTINCT to be disposable...

But that's problem to deal with when you face it

- Lars

rakshetha_jn
Associate
Associate
0 Kudos

This message was moderated.

pratik_doshi2
Participant
0 Kudos

Hi Rakshetha ,

Please have a look at below mentioned link:

From SPS 10 on we have the facility to have the order by in string_agg function.

Please do use these to have more control.

Hope these will help.

-

Pratik