There is, but this, of course, is not obvious:
select * from ( select key, val, col, max(val) over (partition by key) as MaxVal from tableA ) where val = MaxVal
Using over is a great way to do this and does not require any extraneous subqueries. All that is required is to take max val for each key, and then wrap this result set in a subquery, where we can check val on MaxVal to make sure that we pull the correct line.
Much cleaner and faster than up to three subqueries!
Eric
source share