Jump to content

[SOLVED] Many to many relationships


jc2006

Recommended Posts

Hi

I have a problem with table design.

Is it possible to have many to many relationships between 3 tables?
I have a unique situation as follows:

table 1 ---  many to many table  --- table 2
                        |
                        |
                      table 3
Is such a scenario possible?

Thanks

J

Link to comment
https://forums.phpfreaks.com/topic/30366-solved-many-to-many-relationships/
Share on other sites

Sorry, I guess I wasn't specific enough.  Here's an example:

Table 1 lists restaurants: A, B

Table 2 list customers: M, N

Table 3 lists food: X, Y

Table 4: is the many to many relationship between restaurants and customers.
I'll call it restaurants_to_customers.
A --- M
A --- N
B --- N

Table 5: is the many to many relationship between customer and food.
customers_to_food
M -- X
N -- Y


Table 6: is the many to many relationship between restaurant and food.
restaurant to food.
A--X
A--Y
B--Y

A given customer "N" can eat at a given restaurant "A."  And, customer "N" may have eaten a meal "Y" before.  But because of tables above,  is there a way to determine if he ate meal "Y" actually AT restaurant "A" or at a different restaurant "B"?

Put another way, if I listed all the places customer "N" ate at it would include restaurant "A" and "B."  And since both these places serve meal "Y" is there any way to know if the  customer actually ate the meal "Y" at these restaurant A or B? 

Wouldn't it be easiest to create a many_to_many relationship between restaurants, customers, and meals?  I don't think this is possible though.  Or is there a better solution?

I apologize in advance if my explanation is convoluted and makes little sense.

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.