0

I am looking at ordering my rows by their respective parent child relationships. One question has been answered that gets me half way and works but only for 2 levels. See How do I order by parent then child?

As you can see the accepted answer mentions that it only works for 2 levels.

Here is my currently query.

My database looks like this.

car_taxonomy_ID car_taxonomy_parent car_taxonomy_title
1 0 Title
2 1 Title
3 2 Title
4 2 Title
5 1 Title
SELECT *
  FROM car_taxonomy AS feat
  ORDER BY CASE
              WHEN car_taxonomy_parent = 0 THEN car_taxonomy_title
              ELSE (
                SELECT car_taxonomy_title
                FROM   car_taxonomy AS parent
                WHERE  parent.car_taxonomy_ID = feat.car_taxonomy_parent
              )
            END,
            CASE
              WHEN car_taxonomy_parent = 0 THEN 1
            END DESC,
            car_taxonomy_title

But I have one more level to retrieve. What must be modified to get that third level

0 Answers0