All Forums Database
wayneoon 2 posts Joined 06/13
22 Aug 2013
Combining multiple rows into a single row

Hi All,
 
This may have come up before but I'm not getting the answers that I'm seeking for, so I'm going to start a new thread here.
 
Here's the problem:
 
I have a table that stores customer info, let's call it Cust.
The table is loaded by an external process and sometimes it will produce multiple rows.
 
Eg:
 
Cust_Id   Name   Age   TelNo  Address1 Address 2
1             ABC      19      ?         ?                ?
1             ABC                ?        AAAAA         BBBBB
1             ABC      ?       1111    ?                ?
 
In order to avoid multiple rows being selected, I'm trying to write a post-load process that will select rows from this table, and merge the information into a single row , and the expected result should be this:
Cust_Id   Name   Age   TelNo  Address1 Address 2
1             ABC       19      1111   AAAAA    BBBBB
 
Can anyone help to point me to the right direction to get this working? I have been looking at various solutions but none seems to be working as expected. Appreciate the help.

ToddAWalter 316 posts Joined 10/11
22 Aug 2013

SELECT cust_id, name, max(age),max(telno),... GROUP BY cust_id, name;
Hopefully there is some way to identify which rows are new so that these don't get coalesced with prior rows for a customer (eg an effective date).

wayneoon 2 posts Joined 06/13
22 Aug 2013

Thanks Todd!
It helps to push me to the correct direction. Some more work ahead but at least I can progress now. Thanks again.

You must sign in to leave a comment.