Skip to content
Advertisement

Is it possible to get data of two different rows in one row (postgres)

I have this table whereby the data of the same customer id is in a new row:

Is it possible to get a one row of the data like below:

I tried joining but then i get the same as the table where it prints out two data instead of one. Might be my join isn’t correct. Appreciate the help. thanks

Advertisement

Answer

In your case, assuming the missing values be NULL, you may just aggregate by order_id and cust_id and then take the max of the other two columns:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement