I got the following tables:
+-----------------+
| PRODUCTS |
+-----------------+
| #product_id |
| #company_id |
+-----------------+
| |
+---------------------+
| PRODUCT_BUNDLES |
+---------------------+
| #parent_product_id |
| #child_product_id |
| #company_id |
+---------------------+
And here is a result in a tree like of the relationships among ids in the PRODUCT_BUNDLES table for some product:
p1
/ \
p2 p3
/ | \
p4 p5 p6
A user give me the following ids p2, p4, p5 and p6 (the leafs of the tree) and I want return the p1 id (the root of the tree).
How I build select query in mysql to do that?