Na vielleicht hat ich doch eine Idee für die Lösung #2
Code:
SELECT CASE r.flag
WHEN 1 THEN CONCAT( '<' , t.tag, '>', t.`desc` )
WHEN 2 THEN CONCAT( '</' , t.tag, '>')
WHEN 3 THEN CONCAT( '<' , ts.tag, '>', ts.description, '</' , ts.tag, '>')
END AS xml_teil
FROM (SELECT tag, 1 AS flag, lft AS pt, id
FROM tree
UNION ALL
SELECT tag, 2 AS flag, rgt AS pt, id
FROM tree
UNION ALL
SELECT ts.tag, 3 AS flag, ts.lft AS pt, ts.id
FROM tree t
JOIN tree_sub ts
ON ts.id_tree = t.id
ORDER BY pt, tag ) r
LEFT JOIN tree t
ON t.id = r.id
LEFT JOIN tree_sub ts
ON ts.id = r.id
ORDER BY r.pt, r.tag;
+---------------------+
| xml_teil |
+---------------------+
| <A>content A |
| <B>content B |
| </B> |
| <C>content C |
| <C1>content C1 |
| <D>content D |
| <E>content E |
| </E> |
| <F>content F |
| <G>content G |
| <G2>content G1</G2> |
| <G3>content G2</G3> |
| </G> |
| </F> |
| </D> |
| </C> |
| </C1> |
| <H>content H |
| </H> |
| </A> |
+---------------------+
20 rows in set (0.01 sec)
mysql>
Aber so richtig flexibel ist das Ganze immer noch nicht. Vermutlich kommt man bei genauerem Hinsehen (oder bei entsprechenden Anforderungen) nicht um eine echte "Vater/Kind" Lösung. Also um rekursives SQL drum herum.
Grüße
Thomas