pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim C. Nasby <jnasby@pervasive.com>
To: Matt Emmerton <matt@gsicomp.on.ca>
Cc: Russell Simpkins <russellsimpkins@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Help with multistage query
Date: Tue, 4 Oct 2005 17:34:50 -0500
Message-ID: <20051004223450.GM40138@pervasive.com> (raw)
In-Reply-To: <003001c5b3f4$6a6911b0$1200a8c0@gsicomp.on.ca>
References: <000001c5b3d5$a67a3540$0300a8c0@dell8200>
	<BAY103-DAV13C36CCE265B28F7F39B50B5A60@phx.gbl>
	<003001c5b3f4$6a6911b0$1200a8c0@gsicomp.on.ca>

On Wed, Sep 07, 2005 at 05:37:47PM -0400, Matt Emmerton wrote:
> 
>   ----- Original Message ----- 
>   From: Russell Simpkins 
>   To: pgsql-sql@postgresql.org 
>   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=$id;   ; each select returns about 100 records which are saved in a perl variable
> 
>     }
> 
>   how about 
>   select t1.id from t1, t2 where t1.id = t2.id and t2.id = x
> 
> or more correctly, based on the OP's example:
> 
> select t2.x from t1, t2 where t1.id = t2.id and t1.id = <condition>

Actually, I think you want AND t2.x <condition>, not t1.id.

BTW, I recommend not using id as a bareword field name. Very easy to get
confused when you start joining a bunch of stuff together.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



view thread (4+ messages)

Message-ID: <20051004223450.GM40138@pervasive.com>
Permalink:  ../20051004223450.GM40138@pervasive.com/
Also on:    postgresql.org/message-id/20051004223450.GM40138@pervasive.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jnasby@pervasive.com, matt@gsicomp.on.ca, russellsimpkins@hotmail.com
  Subject: Re: Help with multistage query
  In-Reply-To: <20051004223450.GM40138@pervasive.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox