Solved
ID and parentID - how to sort?
Posted on 2002-06-21
Hi, this is a table I've got (if it doesn't look good, paste it into notepad and use system as font... )
tblProjects
-----------------------------------
| ID | parentID | content |
|----------------------------------
| 1 | null | blabla |
| 2 | 1 | blabla |
| 3 | 1 | blabla |
| 4 | null | blabla |
| 5 | 4 | blabla |
| 6 | 4 | blabla |
| 7 | 4 | blabla |
| 8 | null | blabla |
| 9 | 1 | blabla |
| 10 | 1 | blabla |
| 11 | 4 | blabla |
| 12 | 4 | blabla |
-----------------------------------
These are all different projects and instances of projects. Where ID=1, we have a Mother project. ID 2 and ID 3 are children of that Mother Project. Same is found for Mother project 4 and mother project 8.
I want to send a request to the database whereas it replies with the entire list; listing first the mother project, then the parent projects, under each mother object. The result would be something like this:
-----------------------------------
| ID | parentID | content |
|----------------------------------
| 1 | null | blabla |
| 2 | 1 | blabla |
| 3 | 1 | blabla |
| 9 | 1 | blabla |
| 10 | 1 | blabla |
| 4 | null | blabla |
| 5 | 4 | blabla |
| 6 | 4 | blabla |
| 7 | 4 | blabla |
| 11 | 4 | blabla |
| 12 | 4 | blabla |
| 8 | null | blabla |
-----------------------------------
Get my picture? How can I do this?
Any help appreciated,
Kind regards,
Simon