Skip to content
Advertisement

SQL union grouped by rows

Assume I have a table like this:

col1 col2 col3 col4
commonrow one two null
commonrow null null three

How to produce a result to look like this:

col1 col2 col3 col4
commonrow one two three

Thanks

Advertisement

Answer

like this, you can group by col1 and get the maximum in each group:

select col1 , max(col2) col2 , max(col3) col3 , max(col4) col4
from table 
group by col1
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement