If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySql Join Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-04, 10:21
ccline ccline is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
MySql Join Question

I have 3 tables that I have to work with. I have listed all the important information below.

Rights
Rights_Customer_ID
Rights_Product_ID

Product
Product_ID
Product_Customer_ID

Customer
Customer_ID

For every Rights row there is a related Product and Customer. The Customer in this context is really the Customer that the Rights row belongs too.

For every Product row there is a related Customer. Customer in this context is really the Author of the product.

I need to produce is a SELECT statement that can return all Rights rows with the related Products and for each Rights row to return the related Customer. In addition, have each Product return it's related Customer as the Author.

As you can see both the Rights and Product table have an ID for a Customer row but the Customer will not be the same for both.

I'm not sure how to do this with out changing the tables.
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 10:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
PHP Code:
select b.Customer_ID as BelongsTo
     
Product_ID
     
a.Customer_ID as Author
  from Rights 
inner
  join Customer b
    on Rights_Customer_ID 
b.Customer_ID
inner
  join Product
    on Rights_Product_ID 
Product_ID
inner
  join Customer a
    on Product_Customer_ID 
a.Customer_ID 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-15-04, 10:35
ccline ccline is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks

That was very fast reply ) Much appreciated.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On