|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi fellows, I don't have much experience with databases so I was wondering if you guys could help me out.
So here it goes... I have 2 tables, one called event_tbl and the other called venue_tbl. As you can immagine they are for events and venues scheduling. One event can take place up to 4 venues but not necesarily all 4, and no venue can have more than 1 event. These are my tables: event_tbl: event_id event_name event_description event_venue_1 event_venue_2 event_venue_3 event_venue_4 ------------------------------------------------ venue_tbl venue_id venue_name venue_address So how can I get the four venue names with a query, please note that event_venue_1, 2, 3, 4 are supposed to be foreign keys equal to venue_id. Please let me know if I didn't explain myself right, any help is appreciated. |
|
#2
|
||||
|
||||
|
To build this DB correctly, you will need to construct another table, called a bridge table. It will only consist of event_id and venue_id - both are foreign keys, which together, make up a primary key for that table. Once this is done, remove the event_venue_1,2,3,4 fields. This will also allow you to have more venues for an event, should the need arise in the future.
Then, to query an event, and obtain it's venues: Code:
SELECT v.venue_name FROM tblEventVenues ev INNER JOIN venue_tbl v ON ev.venue_id = v.venue_id WHERE ev.event_id = XX |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > a simple mysql query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|