I have got a table structure in mysql like this:
________________________
| id | int(auto) |
|------------------------|
| name | varchar |
|------------------------|
| link | varchar |
|------------------------|
| parent_id| int |
|________________________|
Basically it is a design for a database driven menu, the root menu has parent_id 0, whereas child menu have their root menu specified on parent_id field. It can be up to 3-4 level.
Now, I need to find all child menu under a root menu. I can easily do that for one level menu, but I can’t traverse behind that. I can do that by writing a program (by merging resultsets), but it will be much easier and convenient way, if I can do that using just SQL.
I can’t change any structure of the table or otherwise modify the system. Please help.
I have used the following query to get all the child menu id (comma separated) of a root menu (in this query it is 2). It can support upto 3 levels. I know the query is not optimized and got performance issue, but still I think it is the only way to achieve the solution, without using procedure(which I can’t use).