Re: Optimize the query, help me please.

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: Optimize the query, help me please.
Дата
Msg-id 4ECCD3F1.5000300@iol.ie
обсуждение исходный текст
Ответ на Optimize the query, help me please.  (Капралов Александр<alnkapa@gmail.com>)
Список pgsql-general
On 23/11/2011 10:56, Капралов Александр wrote:
> 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.

(select * from a order by time desc limit 100)
union
(select * from b order by time desc limit 100)
order by time desc limit 100;

BTW "time" is a reserved word AFAIK, so you should enclose it in
double-quotes or call the column something else.

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

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

Предыдущее
От: Капралов Александр
Дата:
Сообщение: Optimize the query, help me please.
Следующее
От: Bèrto ëd Sèra
Дата:
Сообщение: Re: Optimize the query, help me please.