Re: Optimize the query, help me please. - Mailing list pgsql-general

From Achilleas Mantzios
Subject Re: Optimize the query, help me please.
Date
Msg-id 201111231317.21168.achill@matrix.gatewaynet.com
Whole thread Raw
In response to Optimize the query, help me please.  (Капралов Александр<alnkapa@gmail.com>)
List 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 by date:

Previous
From: Bèrto ëd Sèra
Date:
Subject: Re: Optimize the query, help me please.
Next
From: Raghavendra
Date:
Subject: In which catalog postgres Instance Crash time recorded ?