Re: Having a mental block with (self) outer joins - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: Having a mental block with (self) outer joins
Date
Msg-id fui7ho$12e$1@ger.gmane.org
Whole thread Raw
In response to Re: Having a mental block with (self) outer joins  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-sql
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
wastrying 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



pgsql-sql by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: Having a mental block with (self) outer joins
Next
From: Tom Lane
Date:
Subject: Re: Error: could not find pathkey item to sort