I have table like this:
And I would like to bring value item in one row when user_input_id
and question_id
is duplicate.
The result that I wish is this:
Can anyone tell me how to querying it?
Thank You
Advertisement
Answer
You can easily do taht with string_agg(value,’,’) in postgresql.
select user_input_id,question_id, string_agg(value,',') as other_names from table_name group by user_input_id,question_id order by user_input_id,question_id
Output:
You can also have array_aggr() in postgres:
select user_input_id,question_id, array_agg(value::text ) as other_names from table_name group by user_input_id,question_id order by user_input_id,question_id
Output: