Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Nested set level via SQL
29/07/2009
16:01
Avatar
Das123
Member
Members
Forum Posts: 4
Member Since:
29/07/2009
sp_UserOfflineSmall Offline

Many times the nested set model doesn't have a 'level' field. This can be calculated from just the 'lft' and 'rgt' fields although it does add overhead to the mySQL server. Hope this helps someone else. 🙂

This has been adapted from a technique used by Joe Celco and the amazing work he has done with nested sets...

$SQL = sprintf("
SELECT t1.id AS id, t1.title AS title, t1.lft AS lft, t1.rgt AS rgt, COUNT(t2.id) AS level
FROM my_table AS t1, my_table AS t2
WHERE (t1.lft BETWEEN t2.lft AND t2.rgt)
AND (t1.lft > %s AND t1.rgt < %s )
GROUP BY t1.id
HAVING (COUNT(t2.id)= %s )
ORDER BY t1.lft;"
, $n_lft
, $n_rgt
, $n_lvl );       

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
28 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information