If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Stupid Question (Probably)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 19:32
lh21979r lh21979r is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
Question Stupid Question (Probably)

Hi,

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

Example:

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?
Reply With Quote
  #2 (permalink)  
Old 04-06-04, 19:40
SecretAsianMan SecretAsianMan is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
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:
Name
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On