Re: execute same query only one time?

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: execute same query only one time?
Дата
Msg-id EF4F4A1B-1AFF-4109-AF85-B42742583267@gmail.com
обсуждение исходный текст
Ответ на execute same query only one time?  (Johannes <jotpe@posteo.de>)
Ответы Re: execute same query only one time?  (Vitaly Burovoy <vitaly.burovoy@gmail.com>)
Список pgsql-general
> On 08 Feb 2016, at 20:05, Johannes <jotpe@posteo.de> wrote:
>
> select id, col1, col2, ... from t0 where id = (select max(id) from t0
> where col1 = value1 and col2 = value2 and …);


> select col1 from t1 where t0_id = (select max(id) from t0 where col1 =
> value1 and col2 = value2 and …);

select t0.id, t0.col1, t0.col2, t0…., t1.col1
from t0
join t1 on (t1.t0_id = t0.id)
group by t0.id, t0.col1, t0.col2, t0…., t1.col1
having t0.id = max(t0.id);

Low complexity and works with any number of rows from t0 (as does Adrian's solution, btw).
I'm not sure what you mean by "copying of columns" in your reply to Adrian's solution, but I don't think that happens
here.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



В списке pgsql-general по дате отправления:

Предыдущее
От: Johannes
Дата:
Сообщение: Re: execute same query only one time?
Следующее
От: Vitaly Burovoy
Дата:
Сообщение: Re: execute same query only one time?