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

From: Richard Huxton <dev(at)archonet(dot)com>
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
Date: 2006-04-27 17:00:20
Message-ID: 4450F8A4.8000802@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mark Harrison wrote:
>
> ### QUERY 3: combine the two statements above by using two subselects
>
> 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');

This won't work if your LIKE matches more than one row anyway.

Try something like:

SELECT id FROM p4_versions WHERE
(versionof, version) IN (SELECT id,headver FROM p4_files WHERE ...)

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-04-27 17:06:29 Re: query that needs two nested queries, is this the best way?
Previous Message Mark Harrison 2006-04-27 16:50:38 query that needs two nested queries, is this the best way?