Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Having a mental...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3423 of 3661
Post > Topic >>

Having a mental block with (self) outer joins

by spam_eater@[EMAIL PROTECTED] (Thomas Kellerer) Apr 21, 2008 at 03:48 PM

Hi, 

I'm playing around with putting a hierarchy of items into the database.
But for some reason I'm having a mental block understanding the following:

I have a table category with id and parent_id implementing the typical
adjacency model.

To get the first two levels of the hierarchy I use:

SELECT t1.name as lev1, t2.name as lev2
FROM category t1
LEFT JOIN category t2 ON t2.parent = t1.id
WHERE t1.name = 'ROOT'
;

Now what I don't understand is that the root node (which has a NULL
parent_id) is not selected. 

My understanding from the outer join is that it would return all items
from the "left" tables regardless whether they have a corresponding row in
the "right" table. 

So given the data

name, id, parent_id
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. 

I'm sure I'm missing something very obvious, but what?

Thanks in advance 
Thomas


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 4 Posts in Topic:
Having a mental block with (self) outer joins
spam_eater@[EMAIL PROTECT  2008-04-21 15:48:23 
Re: Having a mental block with (self) outer joins
depesz@[EMAIL PROTECTED]   2008-04-21 16:05:21 
Re: Having a mental block with (self) outer joins
spam_eater@[EMAIL PROTECT  2008-04-21 16:15:20 
Re: Having a mental block with (self) outer joins
Dennis Muhlestein <djm  2008-04-24 16:20:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:42:50 CDT 2008.