Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine SQL rows into one row

This is a SQL Server question

I have 3 records with data: (the fields filled with dots are empty!)

NAME   | FIELD1 | FIELD2 | FIELD3 
blabla | .      | b      | . 
blabla | a      | .      | .
blabla | .      | .      | c

Now I want the output to show just one row like this:

blabla | a | b | c

I'm not sure if it has to be a Case or Group or what else

How can i accomplish this?

like image 421
Proxx Avatar asked Jan 13 '23 08:01

Proxx


1 Answers

You can use aggregate function for example max

select name,max(FIELD1) as FIELD1, max(FIELD2) as FIELD2, max(FIELD3) as FIELD3
from tab
group by name
like image 173
Robert Avatar answered Jan 17 '23 13:01

Robert