X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 80604D7FBD for ; Wed, 7 Sep 2005 18:37:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57700-02 for ; Wed, 7 Sep 2005 21:37:39 +0000 (GMT) Received: from skippyii.compar.com (compar.com [216.208.38.130]) by svr1.postgresql.org (Postfix) with ESMTP id 71008D7F9C for ; Wed, 7 Sep 2005 18:37:36 -0300 (ADT) Received: from hermes (CPE00062566c7bb-CM000039c69a66.cpe.net.cable.rogers.com [70.28.254.189]) by skippyii.compar.com (8.13.1/8.13.1) with ESMTP id j87LbuOn099943; Wed, 7 Sep 2005 17:37:59 -0400 (EDT) (envelope-from matt@gsicomp.on.ca) Message-ID: <003001c5b3f4$6a6911b0$1200a8c0@gsicomp.on.ca> From: "Matt Emmerton" To: "Russell Simpkins" , References: <000001c5b3d5$a67a3540$0300a8c0@dell8200> Subject: Re: Help with multistage query Date: Wed, 7 Sep 2005 17:37:47 -0400 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0029_01C5B3D2.DC9937A0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 required=5 tests=[AWL=-0.001, HTML_MESSAGE=0.001] X-Spam-Level: X-Archive-Number: 200509/79 X-Sequence-Number: 22626 This is a multi-part message in MIME format. ------=_NextPart_000_0029_01C5B3D2.DC9937A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ----- Original Message -----=20 From: Russell Simpkins=20 To: pgsql-sql@postgresql.org=20 Sent: Wednesday, September 07, 2005 4:05 PM Subject: Re: [SQL] Help with multistage query I have a perl script that issues a series of SQL statements to = perform some queries. The script works, but I believe there must be a = more elegant way to do this. The simplified queries look like this: SELECT id FROM t1 WHERE condition1; ;returns about 2k records = which are stored in @idarray foreach $id (@idarray) { SELECT x FROM t2 WHERE id=3D$id; ; each select returns about = 100 records which are saved in a perl variable } how about=20 select t1.id from t1, t2 where t1.id =3D t2.id and t2.id =3D x or more correctly, based on the OP's example: select t2.x from t1, t2 where t1.id =3D t2.id and t1.id =3D -- Matt ------=_NextPart_000_0029_01C5B3D2.DC9937A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
----- Original Message -----
From:=20 Russell Simpkins =
Sent: Wednesday, September 07, = 2005 4:05=20 PM
Subject: Re: [SQL] Help with = multistage=20 query
 

I have a perl script = that issues=20 a series of SQL statements to perform some queries.  The script = works,=20 but I believe there must be a more elegant way to do = this.

 

The simplified queries = look like=20 this:

 

SELECT id FROM t1 = WHERE=20 condition1;   ;returns about 2k records which are stored = in=20 @idarray

 

foreach $id (@idarray) = {

   SELECT x = FROM t2=20 WHERE id=3D$id;   ; each select returns about 100 records = which are=20 saved in a perl variable

}

how about
select t1.id from t1, t2 where t1.id = =3D t2.id and=20 t2.id =3D x
 
or more correctly, based on the OP's example:
 
select t2.x from t1, t2 where t1.id =3D t2.id and t1.id = =3D=20 <condition>
 
--
Matt
------=_NextPart_000_0029_01C5B3D2.DC9937A0--