Re: Optimize the query, help me please.

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Капралов Александр <alnkapa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Optimize the query, help me please.
Date: 2011-11-23 11:07:29
Message-ID: 4ECCD3F1.5000300@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bèrto ëd Sèra 2011-11-23 11:08:37 Re: Optimize the query, help me please.
Previous Message Капралов Александр 2011-11-23 10:56:23 Optimize the query, help me please.