I have parent category id in the category table.(same table). When add category there is two options. First one if we create new category without selecting the existence category than its became the parent category. Second one if we create the category with select the existence category that selected category become the parent category. So now i want to select all the category and subcategory by using Cursor and recursive function on sql. This is possible? How?
Asked
Active
Viewed 571 times
1
-
You have to use a cursor? I think it's possible with just joins. – BeemerGuy Nov 12 '10 at 04:29
-
Maybe it's better to do this logic in the application level instead of the database level. It's easier to implement logic in PHP or Java instead of SQL. – Yada Nov 12 '10 at 04:33
2 Answers
0
I can suggest you two very good articles which may help you, however, their approach is different slightly from yours (not using a recursive stored procedure / function, but the MySQL article describes the Nested Set Model, which is brilliant.) The articles are here and here. I hope this helps.

Lajos Arpad
- 64,414
- 37
- 100
- 175
0
MySQL doesn't support recursive queries. There's discussions of various workarounds here: Is it possible to make a recursive SQL query?