Help formulating multi-table SELECT statement

From: Phil Mitchell <phil(dot)mitchell(at)pobox(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Help formulating multi-table SELECT statement
Date: 2002-02-26 18:32:35
Message-ID: 4.3.2.7.2.20020226131505.00ae1910@pop.rcn.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have a simple table model for a many-many r'ship between keys and sigs:

KEYS table has columns: key, keyID
SIGS table has columns: sig, sigID
KEYS_SIGS has columns: keyID, sigID

For a given key X, how can I retrieve all the sigs that are related to it?
Conceptually, I need three SELECTS:

#1. SELECT keyID FROM keys
WHERE key = X

#2. SELECT sigID FROM keys_sigs
WHERE keyID = (result of #1)

SELECT sig FROM sigs
WHERE sigID = (result of #2)

I tried nesting these queries, but PG complained that my subselect had
produced multiple values -- which of course it can.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Jason Earl 2002-02-26 19:07:24 Re: update
Previous Message Masse Jacques 2002-02-26 16:22:45 references and inheritance