Re: A slow query - Help please?

From: "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com>
To: "Alban Hertroys" <alban(at)magproductions(dot)nl>
Cc: "hubert depesz lubaczewski" <depesz(at)gmail(dot)com>, "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: A slow query - Help please?
Date: 2006-06-19 12:00:00
Message-ID: 65937bea0606190500n1718ad1v744dab59e74f3892@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hubert said 'do "something similar" to this'... The syntax was
incorrect for sure.

If you wish to be able to do ORDER BY and LIMIT in UNION queries, you
need to make them sub-queries "something similar" to this:

select * from
(
select * from (select * from only table_a order by number desc limit 25) as A
union
select * from (select * from only table_b order by number desc limit 25) as B
union
select * from (select * from only table_c order by number desc limit 25) as C
) x
order by number desc limit 25;

Again, this query and the syntax is totally untested (I don't have
access to a PG right now); and I don't know much about the history of
this thread!!! But I think it will allow you to do a LIMIT 25 alright.

> And of course 'select *' isn't going to work in the subqueries, the base
> table contains less columns than the inherited tables.

I don't think you have much of an option in that case...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2006-06-19 12:00:05 Re: A slow query - Help please?
Previous Message Florian G. Pflug 2006-06-19 10:34:39 Re: Adding foreign key constraints without integrity check?