Results 1 to 2 of 2

Thread: Link 2 tables

  1. #1
    Join Date
    Jan 2003
    Posts
    5

    Unhappy Unanswered: Link 2 tables

    Hi,

    i have a mysql database and now two tabeles *cool*.
    Now i want to link them over Primary Key. One of the tables have a column where only unique rates are saved. The other one have rows which have more than one of the numbers of table one.

    1 car -> 1 blue,
    1 red,
    1 yellow...
    2 radios -> 2 purple,
    2 black...

    So, i want to save a new car in table1 with few colors. The colors should be saved in table2. The problem is the id from table1 schould saved also in table2 automtically. I dont know how i should do this.

  2. #2
    Join Date
    Jan 2003
    Location
    Duncan BC Canada
    Posts
    80

    Lightbulb

    It's fun when things start to work, isn't it!!

    So you have many items, and many colours. Each item can have many colours, and each colour can be used for many items. This is called a many-to-many relationship. (In fact, what you have may be more complicated, but one step at a time.)

    For a many-to-many relationship, you need a third table. A quick google search on [many-to-many table] came up with an example:

    http://www.faqts.com/knowledge_base/...id/5914/fid/52

    There are plenty of other hits that you could take a look at, too.

    This kind of thing is not RDBMS-specific. You may want to try over in Database Concepts & Design as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •