I have table as
+-------------+----------------------+--------------------+
| category_id | name | parent_category_id |
+-------------+----------------------+--------------------+
| 1 | Pizzas | NULL |
| 2 | Cheese Pizzas | 1 |
| 3 | Spicy Pizzas | 1 |
| 4 | Shakes | NULL |
| 5 | Milk Shakes | 4 |
I have only single level nesting and its going to be the same
I wish to retrieve the rows like
Pizza
Cheese Pizzas
Spicy Pizzas
Shakes
Milk Shakes
Is there something like "Trees" In MySQL as in Oracle, I did read the article http://ftp.nchu.edu.tw/MySQL/tech-resources/articles/hierarchical-data.html
Changing the table structure seems more feasible when there is dynamic levels of nesting, for my case its just going to be 1 throughout
Any Suggestions?
You could use a self-join and do something like:
See it on sqlfiddle.
Or even group the results, if so desired:
See it on sqlfiddle.