pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bernie Huang <bernie.huang@ec.gc.ca>
To: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Big Sub-select statement
Date: Tue, 17 Oct 2000 11:53:42 -0700
Message-ID: <39ECA036.EFF68763@ec.gc.ca> (raw)

Hi,

Let's say if I have a log table with (log_id, emp_id, book_id,
author_id), and there are foreign tables related to each id except the
log_id.  Is it possible to write up a big sub-select statement to
retrieve all possible info?

eg1; (big sub_select)
select ltb.log_id, ltb.emp_id, ltb.book_id, ltb.author_id
from log_tb ltb
where ltb.emp_id in
    (select etb.name
            etb.phone
            etb.email
     from emp_tb etb
     where etb.emp_id=ltb.emp_id)
and ltb.book_id in
    (select btb.name
     ...
    )
and ... [same for author_id];

So, is it possible and efficient to retrieve all info in one big
statement? or is there other better ways to do it?

Right now, here's what I do,
select log_id, emp_id, ...
from log_tb;

while(not end of rows)
{
  select name, phone, email from emp_tb where emp_id=log_tb.emp_id;
  ... [same for book_tb and author_tb]
}

I am thinking if it's in one big statement, then I don't need to look
around in the script to change the select statements.  Thank you.  =)


- Bernie

Attachments:

bernie.huang.vcf (text/x-vcard, 314B) download begin:vcard n:Huang;Bernie tel;fax:(604)664-9195 tel;work:(604)664-9172 x-mozilla-html:TRUE org:Environment Canada;Standards and Technology Services adr:;;700-1200 West 73 Ave.;Vancouver;BC;V6P 6H9;Canada version:2.1 email;internet:bernie.huang@ec.gc.ca title:Programmer x-mozilla-cpt:;0 fn:Bernie Huang end:vcard

Message-ID: <39ECA036.EFF68763@ec.gc.ca>
Permalink:  ../39ECA036.EFF68763@ec.gc.ca/
Also on:    postgresql.org/message-id/39ECA036.EFF68763@ec.gc.ca

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: bernie.huang@ec.gc.ca
  Subject: Re: Big Sub-select statement
  In-Reply-To: <39ECA036.EFF68763@ec.gc.ca>
  References: <39ECA036.EFF68763@ec.gc.ca>

* 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