From: | Andrew Perrin <clists(at)perrin(dot)socsci(dot)unc(dot)edu> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: LIMIT within UNION? |
Date: | 2002-09-12 20:03:54 |
Message-ID: | Pine.LNX.4.21.0209121601370.32000-100000@perrin.socsci.unc.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Thu, 12 Sep 2002, Stephan Szabo wrote:
> 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
Yes - in the (rather rare) case that there are 200 or more eligible
exposure subjects, the result set should be the total number of eligible
exposure subjects.
> and does the
> ... ever include the same person in both sides of the union?
No; each person is only in one of the two sides.
>
> 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.
I'll try that.
>
> 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?
>
Interesting - this would count on the UNION including all cases in the
first query before those in the second query. Are UNIONed records
presented in any predictable order?
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists(at)perrin(dot)socsci(dot)unc(dot)edu * andrew_perrin (at) unc.edu
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-09-12 20:18:19 | Re: LIMIT within UNION? |
Previous Message | Stephan Szabo | 2002-09-12 19:52:26 | Re: LIMIT within UNION? |