Search Postgresql Archives

Re: Optimize the query, help me please.

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

 



Στις 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

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