I have a table "the_table" with three fields: "id" (primary key), "a" and "b". I need select for each "a" the row where "b" has max value for that "a". Then I run the query:
select x.a, x.id
from the_table x
where b = ( select max( b ) where a = x.a )
This query hangs my PostgreSQL server.
I tried another query:
select x.a, max( x.id )
from the_table x
where b = ( select max( b ) where a = x.a )
group by x.a
But the result is the same.
What is wrong in these queries?
Thanks for any reply!
;at the end of your statement. If you are usingpsqlnote that the prompt changed indicating that the statement is not finished and it's waiting for you to end it.