0

I have the following table:

categoryID categoryName parentID

categoryID categoryName parentID
6 Category6 0
7 Category7 0
12 Category12 6
13 Category13 7

How can I get the following order:

categoryID categoryName parentID
6 Category6 0
12 Category12 6
7 Category7 0
13 Category13 7

That is each "child" category to go under it's parent?

I tried with different select and ordering, group by queries, but nothing seems to work.

This question has been marked as duplicate, but it is not. Solution posted on: How to create a MySQL hierarchical recursive query? does not help me, since it shows record for selected category, and I want the whole tree.

D.B.
  • 89
  • 1
  • 9
  • What about doing it application side? – Cid Jun 01 '21 at 14:11
  • I am still trying to re-order the PHP array, without much luck. I hoped SQL will be easier... – D.B. Jun 01 '21 at 14:15
  • https://stackoverflow.com/questions/67788864/how-to-sort-or-group-array-elements-on-base-on-2-different-ids?noredirect=1#comment119819621_67788864 – D.B. Jun 01 '21 at 14:15

0 Answers0