RE: [PHP-DB] Listing parent ids
| From: | Arno Kuhl | Date: | Thu, 28 Jul 2011 09:39:56 +0000 |
| Subject: | RE: [PHP-DB] Listing parent ids | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-47932@lists.php.net to get a copy of this message | ||
Arno Kuhl wrote:
> Not strictly a php issue but it's for a php app, hope that counts
> (plus I haven't had much joy googling this)
>
> 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?
> Or do I have to iterate selecting each parent record while parentid>
> 0 and build the list entry by entry?
Little difficult to answer what you don't say what you are using as a
database.
Recursive queries are now possible on many databases, except I think for
MySQL.
I run this type of query all the time on Firebird and Postgres now supports
the same CTE functions.
--
Lester Caine - G8HFL
-----------------------------
I'm currently using MySQL but I'll switch databases if there's a compelling
reason and no drawbacks.
Thanks for the lead, I'm googling recursive queries.
Cheers
Arno