From: Aaron Bono <postgresql@aranya.com>
To: James Cloos <cloos@jhcloos.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: where clause subqueries vs multiple rows results
Date: Sun, 10 Sep 2006 23:55:02 -0500
Message-ID: <bf05e51c0609102155i1683e18fg47ed27b77113d153@mail.gmail.com> (raw)
In-Reply-To: <bf05e51c0609102154uebc2bc5kebe34b10520d351c@mail.gmail.com>
References: <m3y7srm695.fsf@lugabout.jhcloos.org>
<bf05e51c0609102154uebc2bc5kebe34b10520d351c@mail.gmail.com>
Oops, see correction below...
On 9/10/06, Aaron Bono <postgresql@aranya.com> wrote:
>
> On 9/10/06, James Cloos <cloos@jhcloos.com> wrote:
>
> > 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?
>
>
>
> Will this work?
>
> SELECT guid
> FROM child
> INNER JOIN parent ON (
> child.the_fkey = parent.id
> )
> WHERE name ~ 'some_regex'
> ORDER BY
> child.the_fkey,
> child.my_pkey
> ;
>
> I am not sure what table name is from but since you say it is n+1 queries
> I assume it is from the child table? It would help to know what columns are
> on which tables.
>
> ==================================================================
> Aaron Bono
> Aranya Software Technologies, Inc.
> http://www.aranya.com
> http://codeelixir.com
> ==================================================================
>
--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.comhttp://codeelixir.com
==================================================================
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: postgresql@aranya.com, cloos@jhcloos.com
Subject: Re: where clause subqueries vs multiple rows results
In-Reply-To: <bf05e51c0609102155i1683e18fg47ed27b77113d153@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox