Re: query that needs two nested queries, is this the best way? - Mailing list pgsql-general

From Tom Lane
Subject Re: query that needs two nested queries, is this the best way?
Date
Msg-id 12327.1146157589@sss.pgh.pa.us
Whole thread Raw
In response to query that needs two nested queries, is this the best way?  (Mark Harrison <mh@pixar.com>)
List pgsql-general
Mark Harrison <mh@pixar.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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: query that needs two nested queries, is this the best
Next
From: "Jim Buttafuoco"
Date:
Subject: Re: query that needs two nested queries, is this the best way?