UPDATE from another table?
Could someone give a simple query example for updating one table from another.
The following is the query that's come from Access version of our database. As you should be able to tell, the [contacts] table doesn't have the [company_id] column at the moment and has been previously joined by the [company_name] ... I want to join on the [company_name] and transfer the [company_id] to the contacts table, which will become the new relationship.
UPDATE CONTACTS
INNER JOIN COMPANIES ON COMPANIES.COMPANY_NAME = CONTACTS.COMPANY
SET CONTACTS.COMPANY_ID = COMPANIES.COMPANY_ID;
*** EDIT ***
No sooner than I ask the question and I have worked out the answer, typical, huh
UPDATE CONTACTS
SET CONTACTS.COMPANY_ID = COMPANIES.COMPANY_ID
FROM CONTACTS
INNER JOIN COMPANIES ON (COMPANIES.COMPANY_NAME = CONTACTS.COMPANY)
__________________
Regards,
Sean Anderson
|