|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I have three tables defined as follows :
products -id -name sub_products -product_id -parent_id bundles_lookup -bundle_id -product_id Now, for any given bundle ID, I want to return all the products, and sub-products contained in that bundle. I'm just getting my head around the types of JOIN, but at present I've got something like : SELECT * FROM products LEFT JOIN sub_products ON sub_products.parent_id = products.id OR sub_products.product_id = products.id LEFT JOIN bundles_lookup ON bundles_lookup.product_id = products.id WHERE bundles_lookup.bundle_id = '4' Im having trouble getting all the required products returned in a single row. I can get all the "child" products, or all the parents, but not both (the parent_id ends up in a different row) Any help appreciated. Regards, /Neil/ |
|
#2
|
|||
|
|||
|
I don't have a db up right now, so I can't test this, but try:
Code:
SELECT p.id, p.name, s.parent_id FROM products p LEFT JOIN sub_products s ON s.parent_id = p.id OR s.product_id = p.id LEFT JOIN bundles_lookup b ON b.product_id = p.id WHERE b.bundle_id = 4 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > SQL JOIN help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|