I have 2 tables Product & Product_BOM () where Product is the master table and Product_BOM contains the parts ( bill of materials ) of the products. Please note that a PART (BOM) is another Product.
Table Product
Product_id,Product_name,Product_type ..
Table Product_BOM
Product_Bom_ID, Product_id
on the above tables Product.Product_id = Product_BOM.Product_id
As you can see that a BOM is another product and it may have many other Products as BOM This can be any deeper level. Now the problem is that when the main product is sold i want to decrease the quantity of its BOM (in all its deeper levels and i cant assume the depth). If i have only 2 levels then i can easily JOIN with same table to achieve the result.
SELECT .....
FROM
Product P //Main Product
LEFT JOIN Product_BOM BOM on BOM.Product_id = P.Product_id // Get its BOM
JOIN Product pLevel1 on pLevel1.Product_id = BOM.Product_id // Get BOM's Product name etc
A basic diagram follows
CAR (Main Product)
---TYRE (BOM of LEVEL 1)
-------RUBBER (BOM of LEVEL 2)
---SEAT (BOM of LEVEL 1)
-------LEATHER(BOM of LEVEL 2)
---ENGINE (BOM of LEVEL 1)
-------RPC-AM1(BOM of LEVEL 2)
----------R-18(BOM of LEVEL 3)
----------R-19(BOM of LEVEL 3)
-------CQR-DDF1.0(BOM of LEVEL 2)
On the above all the PART's of the CAR is another Product. Now i have the parent product how i get all the child items belongs to it in any deeper level ?
Is there any other way to achieve the same without JOIN ?