I wasn’t sure what to put into the title for this…please read on…
I have a table of events with 3 days per event
eventID dayID
1 1
1 2
1 3
2 1
2 2
2 3
I also have a number of cars available for the event
carID regNum
1 fg12 bfr
2 gh34 vbn
3 kl56 thg
4 lm32 tfx
I would like to have certain cars available for certain events, for example carIDs 1,2 and 3 might be available for eventID 1 but only carID 4 is available for event 2.
I am unsure how to join these tables together.
I am looking at another table which defines which cars are available to which event for example
eventID carID
1 1
1 2
1 3
2 4
but I can’t work out how to join these 3 tables together to get the car list for event1 for example.
Any pointers gratefully received!
Junction tables are the classic solution for modeling a many-to-many relationship in an RDBMS.
You do not need to join three tables to get cars for event1 – two tables is enough:
If you need the event name, you need to join the event table as well: