mysql - SQL tree traversal -


I am not completely convinced that I am giving this right, but please bear with me.

I am thinking that it is possible to do something like this in SQL (especially MySQL): Suppose we have data like tree which is maintained in the following table in the database:

< Pre> mysql> Desc data_table; + ------------------------ + --------------------- + - - --- + ----- + --------- + ---------------- + | Field | Type | Faucet Key | Default | Extra | + ------------------------ + --------------------- + - - --- + ----- + --------- + ---------------- + | ID | Int (10) unsigned. No | PRI | Faucet Auto_interpretation | | Parents Int (10) unsigned. Yes. Child | Faucet | | Price | Text | Yes. | Faucet |

So there is a parent leaving the 'Root' line in each line, and each line has children leaving leaf rows.

Is it possible to find all the descendants, only what is a line using SQL?

It is possible to bring all the descendents using SQL only, but single queries but me Sure you have understood that out; I believe you want to do this in a single query.

You are interested in reading about some alternative designs to store tree structures, which enable you to bring all the families using a single SQL query. See my presentation.

You can use recursive SQL queries with other brands' database (like PostGreySQL), but MySQL currently does not support this feature.


Comments