Re: Listing parent ids
| From: | Jim Giner | Date: | Thu, 28 Jul 2011 12:24:55 +0000 |
| Subject: | Re: Listing parent ids | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-47939@lists.php.net to get a copy of this message | ||
""Arno Kuhl"" <arno@dotcontent.net> wrote in message
news:487F03135D2B452B89F22C95E278C7D4@point01...
>
> 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 ?