I have two tables. Table1
has company data (Company ID, Company Name ...
), so single record for each company.
Table2
has information about departments in that company (Department ID, Department Name, Company ID, Company Name ...
). So, second table might have n number of records where same company id is used.
Problem is one of our trigger failed to work properly, and no one noticed till now. So, when Company Name was updated in Table1
, it never reflected in Table2
.
To correct this, I have to do something like the below query:
Update Table2
Set
[Company Name] = (select [Company Name]
from Table1
where Table2.Company ID = Table1.Company ID)
Group By Table2.Company ID
Basically, I am trying to update all records in Table2
to use the same name as Table1
, for each record in Table1.
I am a bit confused about how to create the inner select clause.
P.S. Sorry, it might be a bit confusing. Kindly do let me know how to reword it the best.