How to concatenate two columns wrt a Key in PostgreSQL

Viewed 28

I have a table with two keys Call_ID and UUID with their respective Intent and Products. I need to concatenate the two columns with respect to UUID , such that for each UUID their would be unique intent_prouct pairs. The input and output table is given in the image

1 Answers

You can do that using aggregations. ie:

with basedata as (
select Call_Id, UUID, max(Intent) as Intent, Max(Product) as Product
    from myTable
    group by Call_Id, UUID
)
select Call_Id, UUID, Intent || ' ' || Product as Intent_Product
from basedata;
Related