# Thread: joe celko nested set model: how to compute the lft and rgt cols

1. Registered User
Join Date
Jun 2005
Posts
50

## Unanswered: joe celko nested set model: how to compute the lft and rgt cols

Hi,

With reference to http://www.intelligententerprise.com...questid=235427
I want the "sql stmt" which wud give the lft and rgt col values..

i am reading his book but cant understand where he explains
wat lft and rgt cols are..

"The root is always (lft,rgt) (1, 2*(Select count(*)from table) and leaft nodes are (lft+1=rgt)"

2. L O S T in Reality
Join Date
Nov 2005
Location
San Francisco, CA
Posts
506
Originally Posted by dbaguru
Hi,

With reference to http://www.intelligententerprise.com...questid=235427
I want the "sql stmt" which wud give the lft and rgt col values..

i am reading his book but cant understand where he explains
wat lft and rgt cols are..

"The root is always (lft,rgt) (1, 2*(Select count(*)from table) and leaft nodes are (lft+1=rgt)"
My suggestion would be to go through the book again.

Look at the NestTree
node lft rgt
'A' 1 12
'B' 2 3
'C' 4 11
'D' 5 6
'E' 7 8
'F' 9 10

It says : the root is always (lft,rgt)=(1,2 * (SELECT COUNT(*) FROM TreeTable)) and leaf nodes always have (lft+1)=rgt)

Select node AS root
FROM NestTree
WHERE lft=1

i.e root is according to the above 'A' 1 ,12

and leaf node is

SELECT node AS leaf
FROM NestTree
WHERE lft=(rgt-1)

i.e 'B' 2,3
I hope u got it now...

3. Registered User
Join Date
Jun 2005
Posts
50
i understood the relationship between lft and rght cols..
but how on earth do we get the values for those cols in the 1st place...

4. Registered User
Join Date
Jun 2005
Posts
50
dont bother i figured it out...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•