Ad
Group The Two Rows But Last 2 Columns Value Is Different
I have the below table in which I got the data from different tables.
Policy_Number | Name_Of_Client | 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 | Phone | |
---|---|---|---|
BEI/BGAMMQ/0000431 | Test, 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
Related Questions
- → How to make Laravel use my class instead of native PDO?
- → SQL: simple custom column in select doesn't work?
- → How to execute Stored Procedure from Laravel
- → Which database engine type should be specified for Microsoft SQL Database in Laravel?
- → How to troubleshoot PDOException?
- → laravel sql server stored procedure output
- → Issue with converting a date using Carbon
- → SQL microsoft query to Laravel 4.2
- → General error 20018 Cannot Continue the file execution because the session is in the Kill state
- → List names of all available MS SQL databases on server using python
- → Variable which replace DB of name in SSMS
- → Java: database connection. Where is my mistake?
- → How Can I use "Date" Datatype in sql server?
Ad