-1

Simple Question

I have a table that looks like this

enter image description here

I am looking to do is do a select so I can get a result as

enter image description here

Is this a PIVOTING issue? looking for suggestions to see how I can form a 'Select' query for this?

Dale K
  • 25,246
  • 15
  • 42
  • 71
fireholster
  • 622
  • 1
  • 9
  • 22

1 Answers1

1

If you want to merge rows having the same values in the first three columns, then use aggregation:

select columna, columnb,columnc, max(columnd) columnd, max(columne) columne
from mytable
group by columna, columnb, columnc

Aggregate functions - such as max() - ignore null values, so max(columnd) gives you the non-null value across rows having the same (columna, columnb,columnc).

GMB
  • 216,147
  • 25
  • 84
  • 135
  • Thanks for this..there are other columns too, not sure if we want to do aggregate on the select statement. I have put each column in group by then. right? – fireholster Sep 22 '20 at 23:28
  • @fireholster: yes, all columns in the `select` clause that are not in an aggregate function (here, `max()`) must be repeated in the `group by` clause. – GMB Sep 22 '20 at 23:41
  • 1
    I see. Thanks for the Max explanation too. – fireholster Sep 22 '20 at 23:43