travisbrown
Technical User
- Dec 31, 2001
- 1,016
I'm a bit perplexed how to do this. Usually I'd write a recursive function in ASP, but I need this as part of the data results.
I have a categories table.
category_id (pk)
category_name
category_parent
parent_category is so categories can be subjugated to other categories.
1 CAT-A 0
2 CAT-B 0
3 CAT-A1 1
4 CAT-A2 1
5 CAT-A11 3
6 CAT-B1 2
What I need is to return denormalized rows for each category branch like below.
CAT-A/CAT A1/CAT-A11
CAT-A/CAT A2
CAT-B/CAT-B1
Would you start at the lowest node (below) and walk back, or do a forward-looking recursion?
I have a categories table.
category_id (pk)
category_name
category_parent
parent_category is so categories can be subjugated to other categories.
1 CAT-A 0
2 CAT-B 0
3 CAT-A1 1
4 CAT-A2 1
5 CAT-A11 3
6 CAT-B1 2
What I need is to return denormalized rows for each category branch like below.
CAT-A/CAT A1/CAT-A11
CAT-A/CAT A2
CAT-B/CAT-B1
Would you start at the lowest node (below) and walk back, or do a forward-looking recursion?
Code:
SELECT tbl_category.category_id, tbl_category.category_name, tbl_category.category_parent, tbl_category.category_keyword FROM tbl_category LEFT OUTER JOIN tbl_category tbl_category_1 ON tbl_category.category_id = tbl_category_1.category_parent WHERE (tbl_category_1.category_parent IS NULL)