Home > database >  How to concatenate two columns wrt a Key in PostgreSQL
How to concatenate two columns wrt a Key in PostgreSQL

Time:09-07

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

CodePudding user response:

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