Skip to content
Advertisement

How to get highest value for each group by checking with two columns value

I have this table test_table below

So I am trying to return the row which has the highest money. For example, the row return would be like this

But because User ID 1 has the same value for money, I would like to check for the highest year of that money amount and return the result. The expected result should be

Is it possible to get row like this?

Here is the link to test your query online http://sqlfiddle.com/#!9/2e5660/1

Advertisement

Answer

You can try using correlated subquery

DEMO

OUTPUT:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement