I Postgres, I think distinct on
does what you want:
select distinct on (dim, frequency) s.*
from sample_tbl s
order by dim, frequency, date desc, version desc;
For each dim
/frequency
combination this returns one row. That row is the first row encountered based on the order by
clause.