Subject Re: [firebird-support] Re: wrong ordering in WITH RECURSIVE query
Author Richard Damon
On Apr 16, 2019, at 4:40 AM, respektive@... [firebird-support] <firebird-support@yahoogroups.com> wrote:

 

Hi, thank you for reply

But this ordering totaly damage the tree structure

Because PORADI is only relative to parent node, so all child nodes starting with 1

If I change the query as you recommend, the set is sorted in way
1. all first nodes
2. all second nodes
3. all third nodes
....

Any other advices??

Thank you,
Tomas

It sounds like you are forgetting that in SQL, the order of rows is considered unimportant unless there is an explicit order specified AT THAT QUERY (and not in a sub-query used to build that query). That is the nature of the language. If you want the rows in a particular order, then you need to generate something that give it that order.

Any order outside that rule is just a coincidence.

For instance, a sort code for the 3rd node below the 2nd node below node 1 could be 1.0203 (assuming that no node has more than 99 children). Or, if no node has more than 26 children, something like ABC