Re: query that needs two nested queries, is this the best way?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Harrison <mh(at)pixar(dot)com>
Cc: Postgresql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: query that needs two nested queries, is this the best way?
Date: 2006-04-27 17:06:29
Message-ID: 12327.1146157589@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mark Harrison <mh(at)pixar(dot)com> writes:
> I've got a query that depends upon two pieces of data from another table for
> use in a where clause.

> scratch1=# select id from p4_versions where
> versionof=(select id from p4_files where p4path like '%/date.txt')
> and
> version=(select headver from p4_files where p4path like '%/date.txt');

Use a row-wise comparison, viz

select id from p4_versions
where (versionof, version) = (select id, headver from p4_files
where p4path like '%/date.txt');

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Buttafuoco 2006-04-27 17:40:02 Re: query that needs two nested queries, is this the best way?
Previous Message Richard Huxton 2006-04-27 17:00:20 Re: query that needs two nested queries, is this the best