RE: Re: Listing parent ids

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> I have a table with an id and a parentid.
> If it's a top-level record the parentid is 0, otherwise it points to 
> another record, and if that record isn't a top-level record its 
> parentid points to another record, etc (a linked list).
>
> Is there a single select that will return the complete list of parentids?

You say you have a parentid and an id - ie, two specific fields in your
records.  You say that you want to query all the parentids.  Nobody else has
said this, but why not just

Select unique ids where parentid=0  ?  That gives you (as you say) all your
top-level records, which are the parents of everything, no?  Or are you
looking for each id that is itself a parent to something else?  If the
latter, then why not
  select unique parentid where parentid <> 0  ? 

--

Hi Jim. I wanted the list of related parentids from current id to top-level
(parentid=0).
That could be 0 or more results, regardless of how many non-zero parentids
there are in total.
Currently I get this from selecting id=parentid while parentid>0, ie
recursively select each record going up the tree to the top level.
The nested set model apparently can return the entire hierarchical list from
the current node to the top level with a single select, but I haven't run
any tests yet on my specific data.

Cheers
Arno


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux