Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1800CE61693 for ; Thu, 7 Feb 2002 19:00:28 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id g17Num833652 for pgsql-sql@postgresql.org; Thu, 7 Feb 2002 18:56:48 -0500 (EST) (envelope-from news) From: Mark Nielsen X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Looking for the correct solution for a generic problem. Date: Thu, 07 Feb 2002 15:53:02 -0500 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 42 Message-ID: <3C62E92E.3020405@kepnet.net> References: <20020207215234.A6766@superfly.archi-me-des.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: news@hub.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.5) Gecko/20011012 X-Accept-Language: en-us To: pgsql-sql@postgresql.org X-Archive-Number: 200202/90 X-Sequence-Number: 6518 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