Re: Optimize the query, help me please.

Поиск
Список
Период
Сортировка
От Achilleas Mantzios
Тема Re: Optimize the query, help me please.
Дата
Msg-id 201111231317.21168.achill@matrix.gatewaynet.com
обсуждение исходный текст
Ответ на Optimize the query, help me please.  (Капралов Александр<alnkapa@gmail.com>)
Список pgsql-general
Στις Wednesday 23 November 2011 12:56:23 ο/η Капралов Александр έγραψε:
> Query is:
> SELECT * FROM a UNION SELECT * FROM b  ORDER BY time DESC LIMIT 100
>
> how can i get only last 100 row from a and b and then do union. Explain of
> select said that all recond selected from a and b.
>

In order to get 100 last rows from a and 100 last rows from b do:
(SELECT * FROM a ORDER BY time LIMIT 100) UNION ALL (SELECT * FROM b ORDER BY time LIMIT 100);

omitting the "ALL" modifier, you may end up with less rows, since UNION normally returns only
distinct rows.

> thanks.
>



--
Achilleas Mantzios

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

Предыдущее
От: Bèrto ëd Sèra
Дата:
Сообщение: Re: Optimize the query, help me please.
Следующее
От: Raghavendra
Дата:
Сообщение: In which catalog postgres Instance Crash time recorded ?