0

I have table [category], which has fields [id, name, parent_id] - hierarchical data. I have this hierarchical query which find all parents for child with id=259:

SELECT  _id AS id, parent_id,
        @cl := @cl + 1 AS level
FROM    (
        SELECT  @r AS _id,
                    (
                SELECT  @r := parent_id
                FROM    category
                WHERE   id = _id
                ) AS parent_id,
                @l := @l + 1 AS level
        FROM    (
                SELECT  @r := 259,
                        @l := 0,
                        @cl := 0
                ) vars,
                category h
        WHERE   @r <> 0
        ORDER BY
                level DESC
        ) qi

So my questions are:

  1. How to retrieve parents for all records from the table [category], not only for the record with id=259?
  2. How to include name field in this record set?
Dmitrijs
  • 1
  • 1

0 Answers0