Click here to Skip to main content
15,891,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
BRN_NAME MADD1 R1 R2 R3 R4
--------------------------------------------------------------------------
Ashanti Region 1 31 NULL NULL NULL
Ashanti Region 4 NULL NULL NULL 2
Ashanti Region 81 NULL NULL 5 NULL

Greater Accra Region 1 29 NULL NULL NULL
Greater Accra Region 4 NULL NULL NULL 2
Greater Accra Region 81 NULL 7 NULL NULL

Northern Region 1 20 NULL NULL NULL
Northern Region 81 NULL 45 NULL NULL
Northern Region 484 NULL NULL NULL 6



EXPECTED RESULT
===================


BRN_NAME R1 R2 R3 R4
----------------------------------------------------------------------------------
Ashanti Region 31 NULL 5 2

Greater Accra Region 29 7 NULL 2

Northern Region 20 45 NULL 6


Need to reduce multiple rows for each 'BRN_NAME' into a singular row.

How do you achieve it using a select statement

What I have tried:

On going system development challenge
Posted
Updated 15-May-18 8:04am
v2
Comments
Richard MacCutchan 15-May-18 12:34pm    
You need to decide which fields to save from each record.

1 solution

SQL
SELECT
    BRN_NAME,
    Max(R1) As R1,
    Max(R2) As R2,
    Max(R3) As R3,
    Max(R4) As R4
FROM
    YourTable
GROUP BY
    BRN_NAME
;

NB: If there are multiple non-NULL values in one column for a given name, this will return the highest. If that's not what you want, then you'll need to explain how you decide which value to keep.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900