pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Andrew Perrin <clists@perrin.socsci.unc.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: LIMIT within UNION?
Date: Thu, 12 Sep 2002 12:52:26 -0700 (PDT)
Message-ID: <20020912124808.N48644-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <Pine.LNX.4.21.0209121454540.32000-100000@perrin.socsci.unc.edu>

On Thu, 12 Sep 2002, Andrew Perrin wrote:

> Greetings-
>
> I have a table of participants to be contacted for a study. Some are in
> the "exposure" group, others in the "control" group. This is designated by
> a column, typenr, that contains 1 for exposure, 2 for control.
>
> The complication is this: I need to select 200 total. The 200 number
> should include *all* those eligible in the exposure group, plus enough
> from the control group to bring the total number up to 200. (Yes, there is
> a valid reason for this.) Furthermore, I need to sort the output of the
> two groups *together* by zip code.

Do you get more than 200 if there are more eligible people and does the
... ever include the same person in both sides of the union?

If not in the second case, union all would probably save the database
some extra work since it won't have to try to weed out duplicates.

If not in the first case, then wouldn't a limit 200 on the after union
result set work rather than a separate count and subtraction?





view thread (10+ messages)  latest in thread

Message-ID: <20020912124808.N48644-100000@megazone23.bigpanda.com>
Permalink:  ../20020912124808.N48644-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020912124808.N48644-100000@megazone23.bigpanda.com

 · 

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: sszabo@megazone23.bigpanda.com, clists@perrin.socsci.unc.edu
  Subject: Re: LIMIT within UNION?
  In-Reply-To: <20020912124808.N48644-100000@megazone23.bigpanda.com>

* 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