I would like get all rows with h_id max value or NULL if present there. For example result for table below will be:
fid |h_id |
--------|--------|
13374976| |
13377411|66666666|
I tried to write select statement but it returns only max values. How should I extend subselect in this statement for getting correct values?
select
a.fid,
a.h_id
from
my_table a
where
a.h_id = (
select
MAX(sub.h_id)
from
my_table sub
where
sub.FID = a.FID)
group by
a.fid,
a.h_id
order by
a.fid
fid |h_id |
--------|--------|
13374976|58280198|
13374976|58372885|
13374976| |
13377411|58280199|
13377411|66666666|