Having the children come after the parent record would not be too
difficult - but you would have to make some changes.
1) Both the parent name and child name would have to be in the same
column
2) You need two additional columns to track the parent 'number' and
the child 'number'
schema and data would look like this
my_table
rowid name parent_rowid child_number
1 parent1
1 0
2 parent2
2 0
3 child1
2 1
4 child2
2 2
5 parent3
5 0
parent_rowid col
wherever there is a parent you put the parent number (which would be
it's rowid) in the parent_rowid col
otherwise
its a child put its parents rowid in the parent_rowid col
In the child# col
if its a parent, put null or 0
otherwise
if its a child, put its child number
Here's the query:
select name from my_table order by parent_rowid, child_number
Should result in a list: the parent will be listed in order
Parent 1
child of parent 1
child of parent 1
Parent 2
Parent 3
child of parent 3
child of parent 3
etc etc
That's untested and off the top of my head.
Jay Wooten, President
Visual Dynamics, Inc. - Authorized Apple Specialist
www.visdyninc.com
321-773-7788 w
321-773-9604 f
----------------
Everything is easier on a Mac!
----------------
Mac OS 10.4.5
On Apr 18, 2006, at 3:11 PM, Norman Palardy wrote:
On Apr 18, 2006, at 11:52 AM, Trausti Thor Johannsson wrote:
Thank you, but what if the sort order is not important, just that
children would come after the parent record ?
Same solution ? Or is that one possible with a single SQLite
command ?
Trausti
Basically this kid of traversal of a hierarchy is NOT possible in
SQL in a general way.
It requires some kind of iterative or recursive query which SQL
cannot do without some kind of language extensions.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>