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 3DFD8D8241 for ; Wed, 7 Sep 2005 17:05:16 -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 31006-07 for ; Wed, 7 Sep 2005 20:05:05 +0000 (GMT) Received: from hotmail.com (bay103-dav13.bay103.hotmail.com [65.54.174.85]) by svr1.postgresql.org (Postfix) with ESMTP id E4FCCD8134 for ; Wed, 7 Sep 2005 17:05:05 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 7 Sep 2005 13:05:05 -0700 Message-ID: Received: from 65.54.174.200 by BAY103-DAV13.phx.gbl with DAV; Wed, 07 Sep 2005 20:05:05 +0000 X-Originating-IP: [65.54.174.200] X-Originating-Email: [russellsimpkins@hotmail.com] X-Sender: russellsimpkins@hotmail.com From: "Russell Simpkins" To: References: <000001c5b3d5$a67a3540$0300a8c0@dell8200> Subject: Re: Help with multistage query Date: Wed, 7 Sep 2005 16:05:05 -0400 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0185_01C5B3C5.E91FC5F0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-OriginalArrivalTime: 07 Sep 2005 20:05:05.0647 (UTC) FILETIME=[708467F0:01C5B3E7] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.383 required=5 tests=[AWL=-1.405, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, FORGED_MUA_OUTLOOK=3.037, HTML_MESSAGE=0.001, MSGID_FROM_MTA_HEADER=0] X-Spam-Level: *** X-Archive-Number: 200509/76 X-Sequence-Number: 22623 This is a multi-part message in MIME format. ------=_NextPart_000_0185_01C5B3C5.E91FC5F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 ------=_NextPart_000_0185_01C5B3C5.E91FC5F0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 

I have a perl script = that issues a=20 series of SQL statements to perform some queries.  The script = works, but=20 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)=20 {

   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
------=_NextPart_000_0185_01C5B3C5.E91FC5F0--