Fw: Difficult select statement

From: "Derrick Betts" <Derrick(at)grifflink(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Fw: Difficult select statement
Date: 2003-09-25 17:44:01
Message-ID: 009701c3838c$9d050d80$e70a0a0a@BigOne
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Try this:

select * from data where id in(select id from participants where username = 'Harry')

Derrick

----- Original Message -----
From: "Owen Funkhouser" <funk(at)highwaay(dot)net>
To: <pgsql-novice(at)postgresql(dot)org>
Sent: Wednesday, September 24, 2003 6:15 PM
Subject: [NOVICE] Difficult select statement

> I have two tables.
>
> Table "data" has three fields, "id integer", "project text", and "component text".
>
> Table "participants" has two fields, "id integer" and "username text".
>
> The id in each table correspond to the same thing.
>
> The values for each table is as follows:
>
> data
> ----
> 1 | Stocks | Decisions
> 2 | Stocks | Loss
> 3 | Stocks | Profits
> 4 | Bonds | Interest
>
> participants
> ------------
> 1 | George
> 1 | Harry
> 1 | Carmen
> 2 | Owen
> 2 | John
> 3 | Harry
> 4 | Bubba
>
> What I want is a distinct list of id, project, and component where username = Harry.
> Resulting in the following:
>
> 1 | Stocks | Decisions
> 3 | Stocks | Profits
>
> Can this be done in a single SQL statement?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
>

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2003-09-25 17:47:37 Re: Backing Up a Postgres database...
Previous Message Stephan Szabo 2003-09-25 17:29:42 Re: Difficult select statement