1

Topic: To lead sampling to a tree

There are some tables:
A) id, name...
B) id, A_id, name,
C) id, B_id, name
The amount of tables and columns in them can be a miscellaneous
Let's admit I receive sampling of such request:

select A.id, A.name, B.id, B.name, C.id, C.name from A
join B on A.id = B.A_id
join A C on B.id = C.B_id

As on PHP from it to receive a multi-level array that it could be resulted in json and to receive something similar:

[
{
"id":1;
"name": "asdasd";
"B": [
{
"id: 33;
"name": "ghfghfgh";
"C": [
{
"id": 77;
"name": "hfghfgh"
};
{
"id": 887;
"name": "nbmbnm"
}
]
}
]
}
]
]

2

Re: To lead sampling to a tree

Dormedont Evlampievich;
Here it would be advisable to result result of sampling from which the tree already turns out...
Just in case

3

Re: To lead sampling to a tree

Approximate sampling

1, "asdasd", 33, "ghfghfgh", 77, "hfghfgh"
1, "asdasd", 33, "ghfghfgh", 887, "nbmbnm"

Thanks for your example. A question on it, and what if at fio there will be other properties at level mainProject?

4

Re: To lead sampling to a tree

As a matter of fact, at me here a pattern "Linker", i.e. in a tree can be both leaves, and branches.

5

Re: To lead sampling to a tree

Evlampievich wrote:

Thanks for your example. A question on it, and what if at fio there will be other properties at level mainProject?

Look fio = at Peters

Evlampievich wrote:

as a matter of fact, at me here a pattern "Linker", i.e. in a tree can be both leaves, and branches.

it is difficult to tell. At me here not customary tree Parent-Child, namely grouping which gives the structure similar to a tree. The data should be sorted either on the server or on PHP (it is necessary to compare on speed). And then already apply my algorithm, can hardly correct...

6

Re: To lead sampling to a tree

SQLPowerUser wrote:

Look fio = at Peters

At Petrov in a column mainProject some values.
My question was that happens if there will be some columns.