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.
| Author |
Topic |
|
iloveajax
Starting Member
1 Post |
Posted - 2010-03-10 : 08:41:52
|
| Hi,I am working on a product catalogue projectthe project has a product table with structure as follows:ProductId Name ParentProductId ProductDetails 1 A 0 Some Details2 B 1 Some Details3 C 1 Some Details4 D 2 Some Details5 E 0 Some Details6 F 5 Some DetailsThe 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 INNER JOIN [Product] PB ON PA.ProductID = PB.ParentProductID |
 |
|
|
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 projectthe project has a product table with structure as follows:ProductId Name ParentProductId ProductDetails 1 A 0 Some Details2 B 1 Some Details3 C 1 Some Details4 D 2 Some Details5 E 0 Some Details6 F 5 Some DetailsThe 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 followCould you please Look for Recursive CTE in google..you will have plenty of items..Meanwhile let me try to provide a sampple code..MS ACCESShttp://findarticles.com/p/articles/mi_qa4041/is_200704/ai_n19432025/ |
 |
|
|
|
|
|