Combining SQL rows into a single row

This is a SQL Server question.

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

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

Now I want the output to display only one line:

 blabla | a | b | c 

I'm not sure if this should be a case or a group or what else

How can i do this?

+4
source share
1 answer

You can use the aggregate function like max

 select name,max(FIELD1) as FIELD1, max(FIELD2) as FIELD2, max(FIELD3) as FIELD3 from tab group by name 
+9
source

Source: https://habr.com/ru/post/1502803/


All Articles