I have a road_age_test
table:
create table road_age_test (
surface_year int,
base_year int
);
insert into road_age_test (surface_year, base_year) values (10,20);
insert into road_age_test (surface_year, base_year) values (30,null);
insert into road_age_test (surface_year, base_year) values (null,40);
insert into road_age_test (surface_year, base_year) values (null,null);
insert into road_age_test (surface_year, base_year) values (50,50);
commit;
select * from road_age_test;
SURFACE_YEAR BASE_YEAR
------------ ----------
10 20
30 null
null 40
null null
50 50
I would like to select the greatest value from each column, even if one of the values is null:
GREATEST_YEAR
-------------
20
30
40
null
50
What's the simplest way to do this?
Note: Where both values are null
, I want to return null
, not 0
.