Portal Home > Knowledgebase > Articles Database > MYSQL relationship
MYSQL relationship
Posted by cilina, 03-19-2008, 10:41 AM |
Hi all
I'm new with MYSQL & have a question
how can I create relationship between tables?
thanks
|
Posted by etogre, 03-19-2008, 01:43 PM |
You will need to look up information about JOIN's in SQL.
It can be a very confusing subject, read up about it at this link and then go from there.
http://en.wikipedia.org/wiki/Join_(SQL)
|
Posted by Burhan, 03-22-2008, 06:06 AM |
You link tables using the primary keys of the records.
For example, if you have a table called 'authors' with a structure like this:
And now you have a table of books that you want to link to the authors; in your book table -- you would create a column called 'author_id', that would link to the primary key from the authors table:
Now you have a relation between the authors and books table (a one to many relationship -- one author can have many books). So to now, get a listing of all books by an author, you need the id of the author and use that to query the books table:
Hope this helps
|
Add to Favourites Print this Article
Also Read
Support. (Views: 507)