1

Data

  id      cust_name

  1        walmart_ca
  2        ikea_mo
  2        ikea_ca
  2        ikea_in
  1        walmart_in

when i do

  select id,cust_name from test where id=2 

Query returns below output

   id  cust_name

    2  ikea_mo
    2  ikea_ca
    2  ikea_in

How can i get or store the result as single column value as shown below

    id   cust_name

     2   {ikea_mo,ikea_ca,ikea_in}
1

1 Answer 1

2

you should use string_agg function and here is an example for it

select  string_agg(field_1,',') from db.schema.table;

you should mention the separator in your case its , so I am doing string_agg(field_1,',')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.