Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group