Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6378D475F7C for ; Thu, 12 Sep 2002 15:34:24 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id A6A1D475EBD for ; Thu, 12 Sep 2002 15:34:23 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g8CJY7Ko009273; Thu, 12 Sep 2002 15:34:07 -0400 (EDT) To: Andrew Perrin Cc: pgsql-sql@postgresql.org Subject: Re: LIMIT within UNION? In-reply-to: References: Comments: In-reply-to Andrew Perrin message dated "Thu, 12 Sep 2002 15:11:45 -0400" Date: Thu, 12 Sep 2002 15:34:07 -0400 Message-ID: <9272.1031859247@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/112 X-Sequence-Number: 9389 Andrew Perrin writes: > SELECT ... FROM participants > WHERE typenr=1 AND > 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 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