Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 68DFD2E0051 for ; Mon, 21 Apr 2008 11:15:31 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 69851-01 for ; Mon, 21 Apr 2008 11:15:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by developer.postgresql.org (Postfix) with ESMTP id E5A202E0035 for ; Mon, 21 Apr 2008 11:15:28 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Jnwnm-0006wS-1d for pgsql-sql@postgresql.org; Mon, 21 Apr 2008 14:15:26 +0000 Received: from 217.110.94.67 ([217.110.94.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Apr 2008 14:15:26 +0000 Received: from spam_eater by 217.110.94.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Apr 2008 14:15:26 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: Having a mental block with (self) outer joins Date: Mon, 21 Apr 2008 16:15:20 +0200 Lines: 34 Message-ID: References: <20080421140521.GA15223@depesz.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.67 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080213 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 In-Reply-To: <20080421140521.GA15223@depesz.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.197 tagged_above=0 required=5 tests=AWL=-0.402, RCVD_IN_DNSWL_LOW=-1, RCVD_NUMERIC_HELO=2.599 X-Spam-Level: * X-Archive-Number: 200804/125 X-Sequence-Number: 30664 hubert depesz lubaczewski, 21.04.2008 16:05: >> ROOT, 1, NULL >> CHILD1, 2, 1 >> CHILD2, 3, 1 >> >> I would have expected the following result: >> >> ROOT, NULL >> ROOT, CHILD1 >> ROOT, CHILD2 >> >> but the row with (ROOT,NULL) is not returned. > > why would you expect it? > the columns are: parent and child (on your output). > you dont have any row that has *parent_id = 1* and id = NULL. Ah, of course that's where my mental block was ;) Thanks for the quick response > you can get this output though: > > NULL, ROOT > ROOT, CHILD1 > ROOT, CHILD2 > > with this query: > > select p.name as parent, c.name as child from category c left outer join category p on c.parent_id = p.id If the table contains more levels (i.e. child1 being the parent of another item) this bring others back as well. And I was trying to retrieve the full path for each item (I do know the max. number of levels) Cheers, and thanks a lot for the quick response Thomas