Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Recursive Query in MS ACCESS

Author  Topic 

iloveajax
Starting Member

1 Post

Posted - 2010-03-10 : 08:41:52
Hi,

I am working on a product catalogue project

the project has a product table with structure as follows:

ProductId Name ParentProductId ProductDetails

1 A 0 Some Details

2 B 1 Some Details

3 C 1 Some Details

4 D 2 Some Details

5 E 0 Some Details

6 F 5 Some Details

The parentproductId refers to the productId. Thus It has a recursive database structure.(It will have value 0 for the root product).

Such a table structure was created for including more than one level of category.

Could anybody plz let me know how to write a query to find all the subproducts of a particular product based on the productId.



NeilG
Aged Yak Warrior

530 Posts

Posted - 2010-03-10 : 09:28:09
Are you not meaning something like

SELECT PA.ProductID, PA.NAME, PB.NAME as [Category]
FROM [Product] PA I
NNER JOIN [Product] PB ON PA.ProductID = PB.ParentProductID
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 09:47:25
quote:
Originally posted by iloveajax

Hi,

I am working on a product catalogue project

the project has a product table with structure as follows:

ProductId Name ParentProductId ProductDetails

1 A 0 Some Details

2 B 1 Some Details

3 C 1 Some Details

4 D 2 Some Details

5 E 0 Some Details

6 F 5 Some Details

The parentproductId refers to the productId. Thus It has a recursive database structure.(It will have value 0 for the root product).

Such a table structure was created for including more than one level of category.

Could anybody plz let me know how to write a query to find all the subproducts of a particular product based on the productId.






sql server follow
Could you please Look for Recursive CTE in google..you will have plenty of items..Meanwhile let me try to provide a sampple code..

MS ACCESS
http://findarticles.com/p/articles/mi_qa4041/is_200704/ai_n19432025/
Go to Top of Page
   

- Advertisement -