Re: Looking for the correct solution for a generic problem.

Поиск
Список
Период
Сортировка
От Mark Nielsen
Тема Re: Looking for the correct solution for a generic problem.
Дата
Msg-id 3C62E92E.3020405@kepnet.net
обсуждение исходный текст
Ответ на Looking for the correct solution for a generic problem.  (Frank Joerdens <frank@joerdens.de>)
Список 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





В списке pgsql-sql по дате отправления:

Предыдущее
От: Mark Nielsen
Дата:
Сообщение: How do you return more than one variable in a plpgsql function?
Следующее
От: Mark Nielsen
Дата:
Сообщение: Re: Help with a SQL query