I am at a loss here and am not sure what to search for!
I have a table “name” with performer_ID and performer_name.
I have another table ( association ) with a lot of data including 12 name cells which contain the performer_ID number from the “name” table.
The reason for this is that the performer can be in any one or more than one of the 12 cells.
I have a similar problem to the one above for location but there are only two links in the association table this time.
I also have a similar situation for source and here I use a simple join. This works well as the source is only linked in one place.
When displaying the data I need to select the name from the performer table for each of the performers in the association table.
How would I get around the performer problem?
Should I have designed the database in a different way, possibly with a intermediate table?
These are the three tables I mentioned above and the current join I am using.
CREATE TABLE IF NOT EXISTS performer
(
per_ID
smallint(4) NOT NULL AUTO_INCREMENT,
full_name
varchar(50) NOT NULL DEFAULT ‘Name’,
PRIMARY KEY (per_ID
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT=‘List of performers’ AUTO_INCREMENT=19 ;
CREATE TABLE IF NOT EXISTS source
(
sou_ID
smallint(4) NOT NULL AUTO_INCREMENT,
origin
varchar(50) NOT NULL DEFAULT ‘Name’,
PRIMARY KEY (sou_ID
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT=‘Where the record came from’ AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS location
(
loc_ID
smallint(4) NOT NULL AUTO_INCREMENT,
place
varchar(50) NOT NULL DEFAULT ‘Place’,
PRIMARY KEY (loc_ID
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT=‘List of performers’ AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS association
(
ass_ID
int(5) NOT NULL AUTO_INCREMENT COMMENT ‘Identifier’,
performer_1
int(4) NOT NULL COMMENT ‘Artist A1’,
performer_2
int(4) DEFAULT NULL COMMENT ‘Artist A2’,
performer_3
int(4) DEFAULT NULL COMMENT ‘Artist A3’,
performer_4
int(4) DEFAULT NULL COMMENT ‘Artist A4’,
performer_5
int(4) DEFAULT NULL COMMENT ‘Artist A5’,
performer_6
int(4) DEFAULT NULL COMMENT ‘Artist A6’,
performer_7
int(4) NOT NULL COMMENT ‘Artist B1’,
performer_8
int(4) DEFAULT NULL COMMENT ‘Artist B2’,
performer_9
int(4) DEFAULT NULL COMMENT ‘Artist B3’,
performer_10
int(4) DEFAULT NULL COMMENT ‘Artist B4’,
performer_11
int(4) DEFAULT NULL COMMENT ‘Artist B5’,
location_A
int(4) NOT NULL COMMENT ‘Where side A recorded’,
location_B
int(4) NOT NULL COMMENT ‘Where side B recorded’,
source
int(4) NOT NULL COMMENT ‘Source of the record’,
PRIMARY KEY (ass_ID
),
UNIQUE KEY number
(number
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
SELECT * FROM association
JOIN
performer
ON
performer.per_ID=association.performer_1
JOIN
source
ON
source.sou_ID=association.source
JOIN
location
ON
location.loc_ID=association.location_A
WHERE
number = $number ");