Jump to content

Can someone help me understand joins?


Maracles

Recommended Posts

I have just read a large number of tutorials and advice online as well as a book I have here and I don't really understand joins/linking tables.

 

I have created a table called 'title' which has two fields

 

  • titleID - this is the primary key and is an auto-incrementing integer
  • title - this is the films actual title

 

I want to create a table called 'boxoffice' which links a particular film title, via titleID, to its boxoffice results.

 

What I cannot understand is how to take the titleID column I have in the 'title' table and place it in the 'boxoffice' table. Do I simply create a new field in 'boxoffice' called 'titleID' with the same strucutre and then somehow link this with the original 'titleID'? I have tried using the relationship view in phpMyAdmin however when I link to the title.titleID field it does not end up displaying in the boxoffice table. What am I doing wrong?

 

It is important to note that I am NOT trying to output a result that shows a combination of a table, I am actually trying to link the titleID into the boxoffice table so that they are stored together in my database.

 

I know this is a bit of a mess of a an explanation but if someone can help me directly or link me to a decent tutorial that explains all this it would be much appreciated.

 

I am using PHPmyadmin to try and do this however answers in MySQL are also appreciated.

Link to comment
Share on other sites

Hi

 

They are seperate tables. You would have one table with your titleId and title in it, and the box office table would contain the titleId for that particular film. You would have to insert the matching titleId into the box office table.

 

Normally using MySQL you would insert something into the title table and use mysql_insert_id to get the generated titleId, and then you would use that when inserting to the box office table

 

The JOIN would come when you wanted to extract the data and you would link the 2 tables on the titleId.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.