I have a table that contains my node data in a tree view.
Each node has it’s own child. Is it possible to write a single statement to get each node along with it’s children (each level sorted by a date), and their child for as many levels as exists?
- A
- B
- F
- L
- G
- C
- K
- D
- H
- I
- J
- E
So the sql should return
Each node has a parentId, when the parentId is null it means the node is a top level node
- A
- B
- F
- L
- G
- C
- K
- D
- H
- I
- J
- E
EDIT:
Here is my table structure, and it’s on a sqlite file.
I really don’t care about the version or RDBMS as long as I get the correct solution I’ll convert it myself to sqlite and I’ll get it to work
Node Table
___________________
int - nodeId
int - parentId /*referes to nodeId of the parent*/
varchar - title
TimeStamp - dateCreate
As you say you don’t care about the DBMS (even though you use SQLite):
This is the oracle solution:
This is the standard ANSI SQL Solution:
(The only non-standard construct in there is the
lpadfunction which is highly DBMS specific).But I don’t think you’ll be able to “convert” either solution to SQlite