user3801599
user3801599

Reputation: 15

How do I combine/group multiple rows into one row

I'm having issues combining all the rows of the result of my query in one row.

Here's a snapit of my result

Column1    Column2                   Column3           Column4
1900200196 Null                                                          
1900200196 Null
1900200196 Null                      Intake and assmnt/eva
1900200196 Null                                        Staff interpreter 
1900200196 INTERPRETER
1900200196 Null

I would like my result to look like this

Column1     Column2              Column3             Column4
1900200196  MEDICAL INTERPRETER  Staff interpreter   Intake and assmnt/eval

Any assistance in the right direction will do.

Upvotes: 0

Views: 447

Answers (2)

GMB
GMB

Reputation: 222392

Seems like you want aggregation :

with A as (
    select 1900200196 as column1, null as column2, 'INTERPRETER' as column3, 'foo' as column4 FROM DUAL
    UNION
    select 1900200196, 'M', null, null FROM DUAL
)
SELECT column1, MAX(column2) column2, MAX(column3) column3, MAX(column4) column4 FROM A GROUP BY column1
   COLUMN1 | COLUMN2 | COLUMN3     | COLUMN4
---------: | :------ | :---------- | :------
1900200196 | M       | INTERPRETER | foo    

db<>fiddle here

Upvotes: 2

juergen d
juergen d

Reputation: 204746

select column1, 
       max(column2) as column2,
       max(column3) as column3,
       max(column4) as column4
from your_table
group by column1

Upvotes: 3

Related Questions