From: | Andrew Perrin <clists(at)perrin(dot)socsci(dot)unc(dot)edu> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: LIMIT within UNION? |
Date: | 2002-09-12 19:40:46 |
Message-ID: | Pine.LNX.4.21.0209121540130.32000-100000@perrin.socsci.unc.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Thanks! That did it.
The inner parens are necessary - without them the ORDER BY seems to be
parsed as part of the second subquery and is therefore a syntax error.
Best,
Andy
----------------------------------------------------------------------
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
On Thu, 12 Sep 2002, Tom Lane wrote:
> Andrew Perrin <clists(at)perrin(dot)socsci(dot)unc(dot)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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Perrin | 2002-09-12 19:41:51 | Re: LIMIT within UNION? |
Previous Message | Roland Roberts | 2002-09-12 19:35:14 | Re: LIMIT within UNION? |