Ad

Group The Two Rows But Last 2 Columns Value Is Different

- 1 answer

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

Policy_NumberName_Of_ClientEmailPhone
BEI/BGAMMQ/0000431Test, Lda[email protected]NULL
BEI/BGAMMQ/0000431Test, LdaNULL1212121212

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

Policy_NumberName_Of_ClientEmailPhone
BEI/BGAMMQ/0000431Test, Lda[email protected]1212121212

Thank you in advance

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad