From: | Mark Nielsen <python(at)kepnet(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Looking for the correct solution for a generic problem. |
Date: | 2002-02-07 20:53:02 |
Message-ID: | 3C62E92E.3020405@kepnet.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Frank Joerdens wrote:
> I've been wondering about this for quite a while now. And I suspect
> there is a bog-standard way that is better than the rather clumsy
> approach I am following now (it feels clumsy anyway). I've got table B
> which is linked to table A as in
>
> CREATE TABLE A (
> id serial,
> foo text,
> );
>
> CREATE TABLE B (
> a_id int references A (id),
> id serial,
> bar text
> );
>
> Now I want to retrieve rows from A as in
>
> SELECT DISTINCT A.foo
> FROM A,B
> WHERE A.foo [matches some criteria]
> OR B.bar [matches some other criteria]
> AND A.id = B.a_id;
>
Perhaps I am clueless, but wouldn't you want to do this
SELECT DISTINCT A.foo
FROM A,B
WHERE ((A.foo =1)
OR (B.bar =2))
AND A.id = B.a_id;
Actually, I think the outerjoin is right.
I had problems like this in the past. I think the other posts answer it.
Mark
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Nielsen | 2002-02-07 21:02:16 | Re: Help with a SQL query |
Previous Message | Frank Joerdens | 2002-02-07 20:52:34 | Looking for the correct solution for a generic problem. |