Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004

    Question Unanswered: Stupid Question (Probably)


    I am very new to MySQL and well, all database work in general. What I am trying to achieve however is this...


    I have two tables as follows...

    TABLE1 - companies
    FIELDS company_id, company_name

    TABLE2 - people
    FIELDS name, company_name

    I want to only be able to populate the company_name field in TABLE2 with company_names that are present in TABLE1. How would I go about this?

  2. #2
    Join Date
    Apr 2004
    The table design should be tweaked. In most cases, you don't want to have repetitive data in two different tables, in this case, your Company Name field. Table 2 should reference the unique values in Table 1, that is, the Company ID.

    Tweak Table 2 People:
    Company_ID (data should match any value in Companies.company_id)

    If you're designing a front end app, then good design should force the user to choose only those valid company names from the Company table, without having to actually validate it by the time it gets to the back end.

    When you're ready to pull the data, you'll have to do a join against the two tables WHERE Company.Company_ID = People.Company_ID, but you can figure that out yourself!

    Just something to chew on - make sure to have a plan if you have people connected to a company, but you want to delete the company.

    Good luck!

Posting Permissions

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