Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > MYSQL Many-to-Many relationship help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-03, 23:37
danny-can danny-can is offline
Registered User
 
Join Date: Nov 2003
Location: Canada
Posts: 8
Angry MYSQL Many-to-Many relationship help

Hi Folks

Just a newbie looking for some help using MySQL verions 4.016. Here is a DB design with three tables: Members (members address_book), Clubs (list of clubs,addresses,etc) and Positions (list of positions). The relationships between the three tables are as follows:

Club may have many Members...
Members may belong to many Clubs...
Members may have Many positions with different Clubs
Clubs may have many Positions from many Members

-------------------------
CREATE TABLE members (
memberid int(11) NOT NULL auto_increment,
fname varchar(50) default NULL,
lname varchar(50) default NULL,
....other fields ....
PRIMARY KEY (id)
) TYPE=MyISAM;

--------------------------------
CREATE TABLE clubs (
clubno int(12) NOT NULL default '0',
name varchar(30) NOT NULL default '',
contact varchar(30) NOT NULL default '',
....other fields .....
PRIMARY KEY (regno)
) TYPE=MyISAM;

--------------------------------

CREATE TABLE positions (
posid int(2) NOT NULL auto_increment,
positiontitle varchar (50) not null,
PRIMARY KEY (ID)
);

sample data for positions
INSERT INTO position VALUES ('1', 'Chairperson');
INSERT INTO position VALUES ('2', 'Vice Chair');
INSERT INTO position VALUES ('3', 'Past Chair');
INSERT INTO position VALUES ('4', 'Secretary');
INSERT INTO position VALUES ('5', 'Treasurer');
INSERT INTO position VALUES ('6', 'Executive Director');
etc....

----------------------------------

Do I need to create a fourth table to relate my three main tables.

CREATE TABLE relation (
memberid int(11) NOT NULL,
clubno int(12) NOT NULL,
posid int(2) default NULL,
) TYPE=MyISAM;

I need to be able to select all the executive members for each club with their titles...

Any help would be appreciated?

Danny
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 09:43
omiossec omiossec is offline
Registered User
 
Join Date: Jan 2003
Location: Paris, France
Posts: 320
Is for one specif club a member can have One position or many position
__________________
Olivier Miossec
--
http://www.lasso-developpeur.net/
--
Reply With Quote
  #3 (permalink)  
Old 12-09-03, 10:08
danny-can danny-can is offline
Registered User
 
Join Date: Nov 2003
Location: Canada
Posts: 8
One club member can have many positions in many different clubs.
Many positions exists within a club.


Danny
Reply With Quote
  #4 (permalink)  
Old 12-09-03, 14:09
omiossec omiossec is offline
Registered User
 
Join Date: Jan 2003
Location: Paris, France
Posts: 320
Quote:
Originally posted by danny-can
One club member can have many positions in many different clubs.
Many positions exists within a club.


Danny


This not my question for one club (not all), can a member of this club have many or one position ?
__________________
Olivier Miossec
--
http://www.lasso-developpeur.net/
--
Reply With Quote
  #5 (permalink)  
Old 12-18-03, 23:45
aaron_dba aaron_dba is offline
Registered User
 
Join Date: Dec 2003
Posts: 6
Re: MYSQL Many-to-Many relationship help

Sounds way to much like a homework assignment - so a quick pointer instead of an answer. Reread about 3NF, focusing on partial key dependancy.
__________________
/Aaron
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

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