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:
  #1  
Old January 12th, 2004, 11:34 AM
marco48134 marco48134 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 1 marco48134 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question a simple mysql query

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.

Reply With Quote
  #2  
Old January 12th, 2004, 06:53 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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
The process of organising the data as I have above is called normalisation.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > a simple mysql query


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 4 hosted by Hostway
Stay green...Green IT