Maracles Posted March 5, 2010 Share Posted March 5, 2010 Hi, I am trying to design my first link table and struggling despite reading this tutorial: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html#03 I am working on a movie-based site within which each film has its own page. On a page for a specific film there will be a 'Cast' section in which I want to list all actors from the movie. I have three tables; 'title' for the film details. Each film has a unique filmID 'talent' for the cast details. Each actor has a unique talentID 'film2talent' which I aimed to be the link table. Can someone advise what mysql query I would need to link them together? I do not understand how the link table is populated (i.e. do I populate it whenever I add actors or movies to my databae or do I only populate it when I am running a query?) I guess the logic would be: Look in link table for filmID, select all talentIDs that correspond to that filmID and then select all talent information relating to the talentIDs. How do I do this in mysql code though? Any help is MUCH appreciated! Quote Link to comment Share on other sites More sharing options...
ajlisowski Posted March 8, 2010 Share Posted March 8, 2010 You would populate the link table when adding a new actor or movie. So if Chrstian Bale is in like 10 movies, when he is added you would need to add all 10 elements into the link table. To grab what you would need, your query would look similar to this... SELECT m.`film`, a.`name` FROM `title` AS `m` LEFT JOIN `film2talent` AS `l` ON m.`id`=l.`film` LEFT JOIN `talent` AS `a` ON l.`talent`=a.`id` Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.