Answer the question
In order to leave comments, you need to log in
Is it possible to remake a query without using subqueries?
create table test
(
id bigserial primary key,
price_id integer not null,
value integer not null,
time_action timestamp with time zone
)
select distinct price_id, (select value from test t2 where t1.price_id=t2.price_id order by time_action desc limit 1) from test t1
Answer the question
In order to leave comments, you need to log in
select distinct on (price_id), price_id,value from tablename order by price_id, time_action desc
select price_id, value from prices as t1 lateral (select value from test t2 where t1.id=t2.price_id order by time_action desc limit 1) on true;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question