Search Postgresql Archives

Re: Optimize the query, help me please.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux