Re: LIMIT within UNION?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Andrew Perrin <clists(at)perrin(dot)socsci(dot)unc(dot)edu>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: LIMIT within UNION?
Date: 2002-09-12 19:52:26
Message-ID: 20020912124808.N48644-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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?

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Perrin 2002-09-12 20:03:54 Re: LIMIT within UNION?
Previous Message Tim Perdue 2002-09-12 19:49:57 Re: [SQL] Latitude / Longitude