Re: Select from multiple tables

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Jon Earle <je_pgsql(at)kronos(dot)honk(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select from multiple tables
Date: 2003-06-06 19:08:28
Message-ID: Pine.LNX.4.33.0306061259390.20091-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 6 Jun 2003, Jon Earle wrote:

> Hi,
>
> I want to select data from two tables, with the keying information for the
> second table coming from the select results of the first. Can this be
> done in one call, or will I need to resort to two calls - one to get the
> record from the first table, then a second call to get the record from the
> second table based on a key contained in the first results set?

You probably want a join or a sub select.

select * from table1 t1 left join table2 t2 on (t1.id=t2.t1id);

select * from table1 where id in (select id from table2 where compid=3);

Or is it more complex than that?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2003-06-06 19:27:43 Re: Bug in metaphone (contrib/fuzzystrmatch)
Previous Message Ian Barwick 2003-06-06 19:03:09 Re: update phenomenom