Re: where clause subqueries vs multiple rows results

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: James Cloos <cloos(at)jhcloos(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: where clause subqueries vs multiple rows results
Date: 2006-09-11 05:01:29
Message-ID: 20060911050129.13298.qmail@web31814.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-09-11 05:10:09 Re: on connect/on disconnect
Previous Message Aaron Bono 2006-09-11 04:55:02 Re: where clause subqueries vs multiple rows results