M
Das ist schlecht, ich will ja nicht anhand der parentid sortieren, sondern anhand des Wertes in der sort-Spalte. Wenn ich jetzt folgende Tabelle hätte:
+----+----------+-------+------+
| id | parentid | topic | sort |
+----+----------+-------+------+
| 1 | 0 | A | 1 |
| 2 | 0 | B | 0 |
| 3 | 0 | C | 2 |
| 4 | 1 | D | 0 |
| 5 | 1 | E | 1 |
| 6 | 2 | F | 0 |
| 7 | 2 | G | 1 |
+----+----------+-------+------+
Dann will ich die Ausgabe:
+----+----------+-------+------+
| id | parentid | topic | sort |
+----+----------+-------+------+
| 2 | 0 | B | 0 |
| 6 | 2 | F | 0 |
| 7 | 2 | G | 1 |
| 1 | 0 | A | 1 |
| 4 | 1 | D | 0 |
| 5 | 1 | E | 1 |
| 3 | 0 | C | 2 |
+----+----------+-------+------+
Da ich die Wurzel-Knoten A, B und C ja ebenfalls nach sort sortiert haben möchte. Wenn ich jetzt nur eine Ebene habe, dann brauche ich einen join, bei 2 Ebenen schon 2, usw.
(soweit ich mir das vorstelle, habe noch nie versucht so eine Sturktur mit einem Select abzuholen, ausg. Nested-Sets)
Oder irre ich mich da jetzt komplett?
Wenn ich nach parentid, sort sortiere, dann erhalte ich die Liste:
+----+----------+-------+------+
| id | parentid | topic | sort |
+----+----------+-------+------+
| 2 | 0 | B | 0 |
| 1 | 0 | A | 1 |
| 3 | 0 | C | 2 |
| 4 | 1 | D | 0 |
| 5 | 1 | E | 1 |
| 6 | 2 | F | 0 |
| 7 | 2 | G | 1 |
+----+----------+-------+------+