X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 8648F9FA46D for ; Mon, 11 Sep 2006 02:01:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 26338-05 for ; Mon, 11 Sep 2006 05:01:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31814.mail.mud.yahoo.com (web31814.mail.mud.yahoo.com [68.142.206.167]) by postgresql.org (Postfix) with SMTP id B55439F9F80 for ; Mon, 11 Sep 2006 02:01:30 -0300 (ADT) Received: (qmail 13300 invoked by uid 60001); 11 Sep 2006 05:01:29 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=C6MNd6eogpfRUFzds0SaMyaqVjh/cF9n/DnmaHcLvFqV/YrVzO4lh4T0JXgHQn39pJN0wTFs25X0WK+gsVfcw5ICETsmex2ZylRjHDMjMa4UzooHbJQ4yJ2XdyWfYW2imoto3deE0HPltVEcyYbEv0qHrZiqmejiN+jRN4GHpPA= ; Message-ID: <20060911050129.13298.qmail@web31814.mail.mud.yahoo.com> Received: from [24.54.196.198] by web31814.mail.mud.yahoo.com via HTTP; Sun, 10 Sep 2006 22:01:29 PDT Date: Sun, 10 Sep 2006 22:01:29 -0700 (PDT) From: Richard Broersma Jr Subject: Re: where clause subqueries vs multiple rows results To: James Cloos , pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.355 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: *** X-Archive-Number: 200609/62 X-Sequence-Number: 26273 > I've a query which I'd have liked to word akin to: > > SELECT guid FROM child WHERE the_fkey = > ( SELECT id FROM parent WHERE name ~ 'some_regex' ) > ORDER BY the_fkey, my_pkey; > > I got around it by doing the SELECT id first, and then doing a SELECT > guid for each row returned, appending the results together. > > Can that be done in a single query, insead of 1+n queries? select guid from child C join parent P on (C.the_fkey = P.di) Where P.name ~ 'some_regex' order by C.the_fkey, P.my_pkey; Perhaps this might work.