pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Perrin <clists@perrin.socsci.unc.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: LIMIT within UNION?
Date: Thu, 12 Sep 2002 15:34:07 -0400
Message-ID: <9272.1031859247@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.21.0209121454540.32000-100000@perrin.socsci.unc.edu>
References: <Pine.LNX.4.21.0209121454540.32000-100000@perrin.socsci.unc.edu>

Andrew Perrin <clists@perrin.socsci.unc.edu> writes:
> SELECT ... FROM participants
> WHERE typenr=1 AND <eligibility>
> UNION
> SELECT ... FROM participants
> WHERE typenr=2 LIMIT 172
> ORDER BY zip;

I think you need

SELECT * FROM
(
SELECT ... FROM participants
WHERE typenr=1 AND <eligibility>
UNION
(SELECT ... FROM participants
WHERE typenr=2 LIMIT 172)
) ss
ORDER BY zip;

Not sure if the inner set of parens is essential, but it might be.
The outer SELECT superstructure is definitely necessary to give a
place to hang the ORDER BY on.

			regards, tom lane



view thread (10+ messages)  latest in thread

Message-ID: <9272.1031859247@sss.pgh.pa.us>
Permalink:  ../9272.1031859247@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9272.1031859247@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, clists@perrin.socsci.unc.edu
  Subject: Re: LIMIT within UNION?
  In-Reply-To: <9272.1031859247@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox