Re: LIMIT within UNION? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: LIMIT within UNION?
Date
Msg-id 20020912124808.N48644-100000@megazone23.bigpanda.com
Whole thread Raw
In response to LIMIT within UNION?  (Andrew Perrin <clists@perrin.socsci.unc.edu>)
Responses Re: LIMIT within UNION?  (Andrew Perrin <clists@perrin.socsci.unc.edu>)
List 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?




pgsql-sql by date:

Previous
From: Tim Perdue
Date:
Subject: Re: Latitude / Longitude
Next
From: Andrew Perrin
Date:
Subject: Re: LIMIT within UNION?