I have two tables: account_company and document_invoice. Table account_company has 2 columns: company_id and company_name. Table document_invoice has the same columns: company_id and company_name. Something happened and delete all data from column company name from document_invoice.
How can I write SQL query to copy data from account company table to document_invoice? I have been using UPDATE and SET but I don't know exactly how.
UPDATE document_invoice
SET company_name = (SELECT company_name FROM account_company)
WHERE document_id.company_name=document_id.account
This should work:
UPDATE document_invoice t1
SET company_name = t2.company_name
FROM account_company t2
WHERE t1.company_id = t2.company_id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With