Q:

PostgreSQL : How to get a sub-table of rows that have a column which is equal to the MAX of the primary table

What I want to do is to get a sub-table of rows that have a column which is equal to the MAX of the primary table.
I illustrate with an example :

I want to get the ID that have, in priority : 

The lowest VALUE2.
If several rows have the lowest VALUE2 (like in the example), they are differentated by the one who has the highest VALUE1
If several rows have the highest VALUE1 and the lowest VALUE2, they are finally differentiated by the one who has the lowest ID

That is why I want to get subtables, because I have 3 filters of selection. I think this can be done by selecting step by step subtables but if you have a better idea (to improve performance) you can suggest it and I will be thankful :
Firstly, get the subtable of rows that have the lowest VALUE1, then get the sub-sub-table from the sub-table that have the highest VALUE2, then get the "sub-sub-subtable" that have lowest ID.
Anyone knows how to do this with the best performance possible ? (As a matter of fact, the rapidity of the response to this query is important in my application, as there is a lot of clients).
For the moment, I achieve to do this with this query, but it has apparently poor performance :
SELECT MIN(id) INTO id FROM (       SELECT id FROM (
                SELECT id, value1, value2 FROM table WHERE value2 IN (
                        SELECT MIN(value2) FROM table       )
                ) AS reqB WHERE value1 = (

        SELECT MIN(value1) FROM (
                        SELECT id, value1, value2 FROM table WHERE value2 IN (

                SELECT MIN(value2) FROM table           )
                    ) as reqC   ) ) as reqA;

A:

select min(id), value1, value2 
from (
select *,
dense_rank() over(order by value2 asc, value1 desc) as rn
from tablename) t
where t.rn = 1
group by value1, value2;

You can use dense_rank function to get what you need.
Edit: Another solution on similar lines would be to use a row_number function, with all the ordering conditions in the over clause.
select id, value1, value2 
from (
select *,
row_number() over(order by value2 asc, value1 desc, id asc) as rn
from tablename) t
where t.rn = 1

