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

From Roland Roberts
Subject Re: LIMIT within UNION?
Date
Msg-id m27khrovbh.fsf@kuiper.rlent.pnet
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
>>>>> "Andrew" == Andrew Perrin <clists@perrin.socsci.unc.edu> writes:
   Andrew> What I've done is to write a script that counts the number   Andrew> of eligible exposure candidates:
   Andrew> SELECT count(*) FROM participants WHERE <eligibility>   Andrew>  AND typenr=1
   Andrew> Then subtract that number (currently 28) from 200 to get   Andrew> 172 control participants. Then the
problemstarts.
 
   [...]
   Andrew> returns ERROR:  parser: parse error at or near "ORDER"

Can you do this via a subselect:

SELECT * FROM    ( SELECT ... FROM participants     WHERE typenr=1 AND <eligibility>     UNION     SELECT ... FROM
participants    WHERE typenr=2 LIMIT 172 )
 
ORDER BY zip;

roland
--            PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
roland@rlenter.com                     76-15 113th Street, Apt 3B
roland@astrofoto.org                       Forest Hills, NY 11375


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: LIMIT within UNION?
Next
From: Bruno Wolff III
Date:
Subject: Re: [GENERAL] Latitude / Longitude