I have an SQLite database with a simple table of Persons.
Each row represents a person and has four columns: the primary key (id), one for the name, one for the age and one for the parent (points to the primkey id, is NULL if the person has no parent).
Now, I just want to list all those persons sorted on age and have the children grouped with their parent.
For example: (Name, Age)
Dan, 18 Eva, 21 - Bill, 4 - Bull, 7 Steve, 38 Richard, 63 - Ann, 19 - Clara, 39 Vera, 70
This sounds simple, but I cannot figure out the SQL statement 🙁
Thanks in advance!
/John
I recommend you to split this into two queries.
First, get a list of parents:
Then get a properly sorted list of children:
The two lists can then easily be merged on the
id/parentsince they are both sorted first by parent’sage.