Home > Mobile >  Group the two rows but Last 2 columns value is different
Group the two rows but Last 2 columns value is different

Time:02-11

I have the below table in which I got the data from different tables.

Policy_Number Name_Of_Client Email Phone
BEI/BGAMMQ/0000431 Test, Lda [email protected] NULL
BEI/BGAMMQ/0000431 Test, Lda NULL 1212121212

Can someone please help me to get the result as below?

Policy_Number Name_Of_Client Email Phone
BEI/BGAMMQ/0000431 Test, Lda [email protected] 1212121212

Thank you in advance

CodePudding user response:

Aggregate by policy number and name of client, then select the max of the email and phone.

SELECT Policy_Number, Name_Of_Client, MAX(Email) AS Email, MAX(Phone) AS Phone
FROM yourTable
GROUP BY Policy_Number, Name_Of_Client;

By the way, your table in its current state might imply that there is some sort of design or data gathering problem. The output you want is the version you probably should be using.

  • Related