MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old October 21st, 2004, 02:03 AM
spellinn spellinn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 spellinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question SQL JOIN help

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/

Reply With Quote
  #2  
Old December 4th, 2004, 11:20 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > SQL JOIN help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway